Skip to content

Commit b82e01e

Browse files
committed
session: update session remote pub by session ID
It's a better pattern to refer to sessions in the same way consistently. So we update the UpdateSessionRemotePubKey method to use a session ID as a reference to the session instead of local pub key.
1 parent 190d3dc commit b82e01e

File tree

5 files changed

+10
-24
lines changed

5 files changed

+10
-24
lines changed

session/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ type Store interface {
311311
error)
312312

313313
// UpdateSessionRemotePubKey can be used to add the given remote pub key
314-
// to the session with the given local pub key.
315-
UpdateSessionRemotePubKey(ctx context.Context, localPubKey,
314+
// to the session with the given ID.
315+
UpdateSessionRemotePubKey(ctx context.Context, id ID,
316316
remotePubKey *btcec.PublicKey) error
317317

318318
// GetSession fetches the session with the given ID.

session/kvdb_store.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -298,29 +298,19 @@ func (db *BoltStore) NewSession(ctx context.Context, label string, typ Type,
298298
}
299299

300300
// UpdateSessionRemotePubKey can be used to add the given remote pub key
301-
// to the session with the given local pub key.
301+
// to the session with the given ID.
302302
//
303303
// NOTE: this is part of the Store interface.
304-
func (db *BoltStore) UpdateSessionRemotePubKey(_ context.Context, localPubKey,
304+
func (db *BoltStore) UpdateSessionRemotePubKey(_ context.Context, id ID,
305305
remotePubKey *btcec.PublicKey) error {
306306

307-
key := localPubKey.SerializeCompressed()
308-
309307
return db.Update(func(tx *bbolt.Tx) error {
310308
sessionBucket, err := getBucket(tx, sessionBucketKey)
311309
if err != nil {
312310
return err
313311
}
314312

315-
serialisedSession := sessionBucket.Get(key)
316-
317-
if len(serialisedSession) == 0 {
318-
return ErrSessionNotFound
319-
}
320-
321-
session, err := DeserializeSession(
322-
bytes.NewReader(serialisedSession),
323-
)
313+
session, err := getSessionByID(sessionBucket, id)
324314
if err != nil {
325315
return err
326316
}

session/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func newMailboxSession() *mailboxSession {
3636

3737
func (m *mailboxSession) start(session *Session,
3838
serverCreator GRPCServerCreator, authData []byte,
39-
onUpdate func(ctx context.Context, local,
39+
onUpdate func(ctx context.Context, id ID,
4040
remote *btcec.PublicKey) error,
4141
onNewStatus func(s mailbox.ServerStatus)) error {
4242

@@ -53,7 +53,7 @@ func (m *mailboxSession) start(session *Session,
5353
keys := mailbox.NewConnData(
5454
ecdh, session.RemotePublicKey, session.PairingSecret[:],
5555
authData, func(key *btcec.PublicKey) error {
56-
return onUpdate(ctx, session.LocalPublicKey, key)
56+
return onUpdate(ctx, session.ID, key)
5757
}, nil,
5858
)
5959

@@ -112,7 +112,7 @@ func NewServer(serverCreator GRPCServerCreator) *Server {
112112
}
113113

114114
func (s *Server) StartSession(session *Session, authData []byte,
115-
onUpdate func(ctx context.Context, local,
115+
onUpdate func(ctx context.Context, id ID,
116116
remote *btcec.PublicKey) error,
117117
onNewStatus func(s mailbox.ServerStatus)) (chan struct{}, error) {
118118

session/store_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ func TestBasicSessionStore(t *testing.T) {
101101
require.NoError(t, err)
102102
remotePub := remotePriv.PubKey()
103103

104-
err = db.UpdateSessionRemotePubKey(
105-
ctx, session1.LocalPublicKey, remotePub,
106-
)
104+
err = db.UpdateSessionRemotePubKey(ctx, session1.ID, remotePub)
107105
require.NoError(t, err)
108106

109107
// Assert that the session now does have the remote pub key.

session_rpcserver.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,9 +1245,7 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
12451245
"autopilot server: %v", err)
12461246
}
12471247

1248-
err = s.cfg.db.UpdateSessionRemotePubKey(
1249-
ctx, sess.LocalPublicKey, remoteKey,
1250-
)
1248+
err = s.cfg.db.UpdateSessionRemotePubKey(ctx, sess.ID, remoteKey)
12511249
if err != nil {
12521250
return nil, fmt.Errorf("error setting remote pubkey: %v", err)
12531251
}

0 commit comments

Comments
 (0)