Skip to content

Commit 259ad26

Browse files
committed
multi: add quit channel to mailboxSession
Add a quit channel to mailboxSession that will be closed on session close. This is also returned from the StartSession function so that, in a future commit, the channel can be listened on.
1 parent a743c7c commit 259ad26

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

session/server.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ type GRPCServerCreator func(opts ...grpc.ServerOption) *grpc.Server
1919
type mailboxSession struct {
2020
server *grpc.Server
2121

22-
wg sync.WaitGroup
22+
wg sync.WaitGroup
23+
quit chan struct{}
24+
}
25+
26+
func newMailboxSession() *mailboxSession {
27+
return &mailboxSession{
28+
quit: make(chan struct{}),
29+
}
2330
}
2431

2532
func (m *mailboxSession) start(session *Session,
@@ -62,6 +69,7 @@ func (m *mailboxSession) run(mailboxServer *mailbox.Server) {
6269

6370
func (m *mailboxSession) stop() {
6471
m.server.Stop()
72+
close(m.quit)
6573
m.wg.Wait()
6674
}
6775

@@ -82,7 +90,9 @@ func NewServer(serverCreator GRPCServerCreator) *Server {
8290
}
8391
}
8492

85-
func (s *Server) StartSession(session *Session, authData []byte) error {
93+
func (s *Server) StartSession(session *Session, authData []byte) (chan struct{},
94+
error) {
95+
8696
s.activeSessionsMtx.Lock()
8797
defer s.activeSessionsMtx.Unlock()
8898

@@ -91,11 +101,13 @@ func (s *Server) StartSession(session *Session, authData []byte) error {
91101

92102
_, ok := s.activeSessions[id]
93103
if ok {
94-
return fmt.Errorf("session %x is already active", id[:])
104+
return nil, fmt.Errorf("session %x is already active", id[:])
95105
}
96106

97-
s.activeSessions[id] = &mailboxSession{}
98-
return s.activeSessions[id].start(session, s.serverCreator, authData)
107+
sess := newMailboxSession()
108+
s.activeSessions[id] = sess
109+
110+
return sess.quit, sess.start(session, s.serverCreator, authData)
99111
}
100112

101113
func (s *Server) StopSession(localPublicKey *btcec.PublicKey) error {

session_rpcserver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ func (s *sessionRpcServer) resumeSession(sess *session.Session) error {
105105
}
106106

107107
authData := []byte("Authorization: Basic " + s.basicAuth)
108-
return s.sessionServer.StartSession(sess, authData)
108+
_, err := s.sessionServer.StartSession(sess, authData)
109+
return err
109110
}
110111

111112
// ListSessions returns all sessions known to the session store.

0 commit comments

Comments
 (0)