init ephemeralService right away in service cache to avoid potential segfaults
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Dan Ballard 2021-12-20 11:59:23 -05:00
parent 069c754595
commit 42e04c17c3
1 changed files with 4 additions and 8 deletions

View File

@ -339,7 +339,7 @@ func (e *engine) peerWithTokenServer(onion string, tokenServerOnion string, toke
// Otherwise...let's reconnect
}
connectionService = &connectionLockedService{}
connectionService = &connectionLockedService{service: new(tor.BaseOnionService)}
e.ephemeralServices[onion] = connectionService
connectionService.connectingLock.Lock()
@ -349,20 +349,16 @@ func (e *engine) peerWithTokenServer(onion string, tokenServerOnion string, toke
log.Debugf("Peering with Token Server %v %v", onion, tokenServerOnion)
e.ignoreOnShutdown(e.serverConnecting)(onion)
// Create a new ephemeral service for this connection
ephemeralService := new(tor.BaseOnionService)
eid, epk := primitives.InitializeEphemeralIdentity()
ephemeralService.Init(e.acn, epk, &eid)
connectionService.service.Init(e.acn, epk, &eid)
Y := ristretto255.NewElement()
Y.UnmarshalText([]byte(tokenServerY))
connected, err := ephemeralService.Connect(onion, NewTokenBoardClient(e.acn, Y, tokenServerOnion, lastKnownSignature, e.receiveGroupMessage, e.serverAuthed, e.serverSynced, e.ignoreOnShutdown(e.serverDisconnected)))
e.ephemeralServicesLock.Lock()
e.ephemeralServices[onion].service = ephemeralService
e.ephemeralServicesLock.Unlock()
connected, err := connectionService.service.Connect(onion, NewTokenBoardClient(e.acn, Y, tokenServerOnion, lastKnownSignature, e.receiveGroupMessage, e.serverAuthed, e.serverSynced, e.ignoreOnShutdown(e.serverDisconnected)))
// If we are already connected...check if we are authed and issue an auth event
// (This allows the ui to be stateless)
if connected && err != nil {
conn, err := ephemeralService.GetConnection(onion)
conn, err := connectionService.service.GetConnection(onion)
if err == nil {
// If the server is synced, resend the synced status update