Merge pull request 'add more safety checks around new engine ephemeral locking to avoid segfault on exit' (#420) from segExit into master
continuous-integration/drone/push Build is pending Details
continuous-integration/drone/tag Build is passing Details

Reviewed-on: #420
Reviewed-by: Sarah Jamie Lewis <sarah@openprivacy.ca>
This commit is contained in:
Dan Ballard 2021-12-20 18:19:53 +00:00
commit 4d999f7914
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