@@ -87,6 +87,9 @@ type EEBus struct {
8787 // unknown ski may still belong to a device that is not configured yet.
8888 configured bool
8989
90+ // pending contains pairing requests received while still configuring
91+ pending map [string ]shipapi.ServiceIdentity
92+
9093 ski string
9194
9295 paired []shipapi.ServiceIdentity // devices paired via SHIP Pairing Service
@@ -122,8 +125,21 @@ func ConfigComplete() {
122125 }
123126
124127 instance .mux .Lock ()
125- defer instance .mux .Unlock ()
126128 instance .configured = true
129+
130+ // deny requests left pending during configuration whose ski remained unknown
131+ var deny []shipapi.ServiceIdentity
132+ for _ , identity := range instance .pending {
133+ if len (instance .clients [identity .SKI ]) == 0 {
134+ deny = append (deny , identity )
135+ }
136+ }
137+ clear (instance .pending )
138+ instance .mux .Unlock ()
139+
140+ for _ , identity := range deny {
141+ instance .service .CancelPairing (identity )
142+ }
127143}
128144
129145func GetStatus () any {
@@ -207,10 +223,16 @@ func NewServer(other Config) (*EEBus, error) {
207223 ski : ski ,
208224 clients : make (map [string ][]Device ),
209225 connected : make (map [string ]bool ),
226+ pending : make (map [string ]shipapi.ServiceIdentity ),
210227 }
211228
212229 c .service = service .NewService (configuration , c )
213230 c .service .SetLogging (c )
231+
232+ // keep pairing requests from unknown skis pending instead of aborting the ship
233+ // handshake- the ski may still be registered by a device that is being configured
234+ c .service .UserIsAbleToApproveOrCancelPairingRequests (true )
235+
214236 if err := c .service .Setup (); err != nil {
215237 if errors .Is (err , shipapi .ErrInvalidSKI ) {
216238 const hint = "The stored EEBUS certificate has an invalid Subject Key Identifier (SKI).\n " +
@@ -587,6 +609,7 @@ func (c *EEBus) ServicePairingDetailUpdate(identity shipapi.ServiceIdentity, det
587609 // device configuration is still running- leave the request pending
588610 // instead of denying a ski that is about to be registered
589611 c .log .DEBUG .Printf ("pairing request from %s while configuring, left pending" , identity .SKI )
612+ c .pending [identity .SKI ] = identity
590613 return
591614 }
592615
@@ -601,16 +624,22 @@ func (c *EEBus) ServiceAutoTrusted(service eebusapi.ServiceInterface, identity s
601624 c .log .INFO .Printf ("service trusted: %s" , identity .ShipID )
602625
603626 c .mux .Lock ()
604- defer c .mux .Unlock ()
605627 c .upsertPairing (identity )
606628
607629 // connect may run before trust is established, so clientsFor skips consumers
608630 // registered without ski; wake them now that the device is paired
631+ var clients []Device
609632 if c .connected [identity .SKI ] {
610- for _ , client := range c .clientsFor (identity .SKI ) {
611- client .Connect (true )
612- }
633+ clients = c .clientsFor (identity .SKI )
613634 }
635+ c .mux .Unlock ()
636+
637+ for _ , client := range clients {
638+ client .Connect (true )
639+ }
640+
641+ // registering the now trusted identity approves a handshake still pending trust
642+ c .service .RegisterRemoteService (identity )
614643}
615644
616645func (c * EEBus ) ServiceAutoTrustFailed (service eebusapi.ServiceInterface , identity shipapi.ServiceIdentity , reason error ) {
0 commit comments