@@ -31,6 +31,7 @@ import (
31
31
"github.com/ethereum/go-ethereum/rlp"
32
32
"github.com/ethereum/go-ethereum/rpc"
33
33
"github.com/ethersphere/swarm/log"
34
+ "github.com/ethersphere/swarm/pss/message"
34
35
)
35
36
36
37
const (
@@ -54,7 +55,7 @@ type handshakeMsg struct {
54
55
Limit uint16
55
56
Keys [][]byte
56
57
Request uint8
57
- Topic Topic
58
+ Topic message. Topic
58
59
}
59
60
60
61
// internal representation of an individual symmetric key
@@ -112,8 +113,8 @@ type HandshakeController struct {
112
113
symKeySendLimit uint16
113
114
symKeyCapacity uint8
114
115
symKeyIndex map [string ]* handshakeKey
115
- handshakes map [string ]map [Topic ]* handshake
116
- deregisterFuncs map [Topic ]func ()
116
+ handshakes map [string ]map [message. Topic ]* handshake
117
+ deregisterFuncs map [message. Topic ]func ()
117
118
}
118
119
119
120
// Attach HandshakeController to pss node
@@ -128,8 +129,8 @@ func SetHandshakeController(pss *Pss, params *HandshakeParams) error {
128
129
symKeySendLimit : params .SymKeySendLimit ,
129
130
symKeyCapacity : params .SymKeyCapacity ,
130
131
symKeyIndex : make (map [string ]* handshakeKey ),
131
- handshakes : make (map [string ]map [Topic ]* handshake ),
132
- deregisterFuncs : make (map [Topic ]func ()),
132
+ handshakes : make (map [string ]map [message. Topic ]* handshake ),
133
+ deregisterFuncs : make (map [message. Topic ]func ()),
133
134
}
134
135
api := & HandshakeAPI {
135
136
namespace : "pss" ,
@@ -147,7 +148,7 @@ func SetHandshakeController(pss *Pss, params *HandshakeParams) error {
147
148
148
149
// Return all unexpired symmetric keys from store by
149
150
// peer (public key), topic and specified direction
150
- func (ctl * HandshakeController ) validKeys (pubkeyid string , topic * Topic , in bool ) (validkeys []* string ) {
151
+ func (ctl * HandshakeController ) validKeys (pubkeyid string , topic * message. Topic , in bool ) (validkeys []* string ) {
151
152
ctl .lock .Lock ()
152
153
defer ctl .lock .Unlock ()
153
154
now := time .Now ()
@@ -177,11 +178,11 @@ func (ctl *HandshakeController) validKeys(pubkeyid string, topic *Topic, in bool
177
178
178
179
// Add all given symmetric keys with validity limits to store by
179
180
// peer (public key), topic and specified direction
180
- func (ctl * HandshakeController ) updateKeys (pubkeyid string , topic * Topic , in bool , symkeyids []string , limit uint16 ) {
181
+ func (ctl * HandshakeController ) updateKeys (pubkeyid string , topic * message. Topic , in bool , symkeyids []string , limit uint16 ) {
181
182
ctl .lock .Lock ()
182
183
defer ctl .lock .Unlock ()
183
184
if _ , ok := ctl .handshakes [pubkeyid ]; ! ok {
184
- ctl .handshakes [pubkeyid ] = make (map [Topic ]* handshake )
185
+ ctl .handshakes [pubkeyid ] = make (map [message. Topic ]* handshake )
185
186
186
187
}
187
188
if ctl.handshakes [pubkeyid ][* topic ] == nil {
@@ -214,14 +215,14 @@ func (ctl *HandshakeController) updateKeys(pubkeyid string, topic *Topic, in boo
214
215
}
215
216
}
216
217
217
- func (ctl * HandshakeController ) releaseKey (symkeyid string , topic * Topic ) bool {
218
+ func (ctl * HandshakeController ) releaseKey (symkeyid string , topic * message. Topic ) bool {
218
219
ctl .lock .Lock ()
219
220
defer ctl .lock .Unlock ()
220
221
return ctl .releaseKeyNoLock (symkeyid , topic )
221
222
}
222
223
223
224
// Expire a symmetric key, making it eligible for garbage collection
224
- func (ctl * HandshakeController ) releaseKeyNoLock (symkeyid string , topic * Topic ) bool {
225
+ func (ctl * HandshakeController ) releaseKeyNoLock (symkeyid string , topic * message. Topic ) bool {
225
226
if ctl .symKeyIndex [symkeyid ] == nil {
226
227
log .Debug ("no symkey" , "symkeyid" , symkeyid )
227
228
return false
@@ -236,7 +237,7 @@ func (ctl *HandshakeController) releaseKeyNoLock(symkeyid string, topic *Topic)
236
237
// Expired means:
237
238
// - expiry timestamp is set, and grace period is exceeded
238
239
// - message validity limit is reached
239
- func (ctl * HandshakeController ) cleanHandshake (pubkeyid string , topic * Topic , in bool , out bool ) int {
240
+ func (ctl * HandshakeController ) cleanHandshake (pubkeyid string , topic * message. Topic , in bool , out bool ) int {
240
241
ctl .lock .Lock ()
241
242
defer ctl .lock .Unlock ()
242
243
var deletecount int
@@ -378,7 +379,7 @@ func (ctl *HandshakeController) handleKeys(pubkeyid string, keymsg *handshakeMsg
378
379
// If number of valid outgoing keys is less than the ideal/max
379
380
// amount, a request is sent for the amount of keys to make up
380
381
// the difference
381
- func (ctl * HandshakeController ) sendKey (pubkeyid string , topic * Topic , keycount uint8 ) ([]string , error ) {
382
+ func (ctl * HandshakeController ) sendKey (pubkeyid string , topic * message. Topic , keycount uint8 ) ([]string , error ) {
382
383
383
384
var requestcount uint8
384
385
to := PssAddress {}
@@ -392,7 +393,7 @@ func (ctl *HandshakeController) sendKey(pubkeyid string, topic *Topic, keycount
392
393
recvkeyids := make ([]string , keycount )
393
394
ctl .lock .Lock ()
394
395
if _ , ok := ctl .handshakes [pubkeyid ]; ! ok {
395
- ctl .handshakes [pubkeyid ] = make (map [Topic ]* handshake )
396
+ ctl .handshakes [pubkeyid ] = make (map [message. Topic ]* handshake )
396
397
}
397
398
ctl .lock .Unlock ()
398
399
@@ -479,7 +480,7 @@ type HandshakeAPI struct {
479
480
//
480
481
// Fails if the incoming symmetric key store is already full (and `flush` is false),
481
482
// or if the underlying key dispatcher fails
482
- func (api * HandshakeAPI ) Handshake (pubkeyid string , topic Topic , sync bool , flush bool ) (keys []string , err error ) {
483
+ func (api * HandshakeAPI ) Handshake (pubkeyid string , topic message. Topic , sync bool , flush bool ) (keys []string , err error ) {
483
484
var hsc chan []string
484
485
var keycount uint8
485
486
if flush {
@@ -512,13 +513,13 @@ func (api *HandshakeAPI) Handshake(pubkeyid string, topic Topic, sync bool, flus
512
513
}
513
514
514
515
// Activate handshake functionality on a topic
515
- func (api * HandshakeAPI ) AddHandshake (topic Topic ) error {
516
+ func (api * HandshakeAPI ) AddHandshake (topic message. Topic ) error {
516
517
api .ctrl .deregisterFuncs [topic ] = api .ctrl .pss .Register (& topic , NewHandler (api .ctrl .handler ))
517
518
return nil
518
519
}
519
520
520
521
// Deactivate handshake functionality on a topic
521
- func (api * HandshakeAPI ) RemoveHandshake (topic * Topic ) error {
522
+ func (api * HandshakeAPI ) RemoveHandshake (topic * message. Topic ) error {
522
523
if _ , ok := api .ctrl .deregisterFuncs [* topic ]; ok {
523
524
api .ctrl .deregisterFuncs [* topic ]()
524
525
}
@@ -531,7 +532,7 @@ func (api *HandshakeAPI) RemoveHandshake(topic *Topic) error {
531
532
// The `in` and `out` parameters indicate for which direction(s)
532
533
// symmetric keys will be returned.
533
534
// If both are false, no keys (and no error) will be returned.
534
- func (api * HandshakeAPI ) GetHandshakeKeys (pubkeyid string , topic Topic , in bool , out bool ) (keys []string , err error ) {
535
+ func (api * HandshakeAPI ) GetHandshakeKeys (pubkeyid string , topic message. Topic , in bool , out bool ) (keys []string , err error ) {
535
536
if in {
536
537
for _ , inkey := range api .ctrl .validKeys (pubkeyid , & topic , true ) {
537
538
keys = append (keys , * inkey )
@@ -570,7 +571,7 @@ func (api *HandshakeAPI) GetHandshakePublicKey(symkeyid string) (string, error)
570
571
// If `flush` is set, garbage collection will be performed before returning.
571
572
//
572
573
// Returns true on successful removal, false otherwise
573
- func (api * HandshakeAPI ) ReleaseHandshakeKey (pubkeyid string , topic Topic , symkeyid string , flush bool ) (removed bool , err error ) {
574
+ func (api * HandshakeAPI ) ReleaseHandshakeKey (pubkeyid string , topic message. Topic , symkeyid string , flush bool ) (removed bool , err error ) {
574
575
removed = api .ctrl .releaseKey (symkeyid , & topic )
575
576
if removed && flush {
576
577
api .ctrl .cleanHandshake (pubkeyid , & topic , true , true )
@@ -582,7 +583,7 @@ func (api *HandshakeAPI) ReleaseHandshakeKey(pubkeyid string, topic Topic, symke
582
583
//
583
584
// Overloads the pss.SendSym() API call, adding symmetric key usage count
584
585
// for message expiry control
585
- func (api * HandshakeAPI ) SendSym (symkeyid string , topic Topic , msg hexutil.Bytes ) (err error ) {
586
+ func (api * HandshakeAPI ) SendSym (symkeyid string , topic message. Topic , msg hexutil.Bytes ) (err error ) {
586
587
err = api .ctrl .pss .SendSym (symkeyid , topic , msg [:])
587
588
if otherErr := api .ctrl .registerSymKeyUse (symkeyid ); otherErr != nil {
588
589
return otherErr
0 commit comments