From 42e04c17c35ac230eeae7a8e9470950b481ff8e2 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Mon, 20 Dec 2021 11:59:23 -0500 Subject: [PATCH] init ephemeralService right away in service cache to avoid potential segfaults --- protocol/connections/engine.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/protocol/connections/engine.go b/protocol/connections/engine.go index 067c9f2..3069b6f 100644 --- a/protocol/connections/engine.go +++ b/protocol/connections/engine.go @@ -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