@@ -72,6 +72,11 @@ const (
7272 RetrievalEnabled
7373)
7474
75+ // subscriptionFunc is used to determine what to do in order to perform subscriptions
76+ // usually we would start to really subscribe to nodes, but for tests other functionality may be needed
77+ // (see TestRequestPeerSubscriptions in streamer_test.go)
78+ var subscriptionFunc func (r * Registry , p * network.Peer , bin uint8 , subs map [enode.ID ]map [Stream ]struct {}) bool = doRequestSubscription
79+
7580// Registry registry for outgoing and incoming streamer constructors
7681type Registry struct {
7782 addr enode.ID
@@ -90,10 +95,6 @@ type Registry struct {
9095 spec * protocols.Spec //this protocol's spec
9196 balance protocols.Balance //implements protocols.Balance, for accounting
9297 prices protocols.Prices //implements protocols.Prices, provides prices to accounting
93- // the subscriptionFunc is used to determine what to do in order to perform subscriptions
94- // usually we would start to really subscribe to nodes, but for tests other functionality may be needed
95- // (see TestRequestPeerSubscriptions in streamer_test.go)
96- subscriptionFunc func (p * network.Peer , bin uint8 , subs map [enode.ID ]map [Stream ]struct {}) bool
9798}
9899
99100// RegistryOptions holds optional values for NewRegistry constructor.
@@ -128,8 +129,7 @@ func NewRegistry(localID enode.ID, delivery *Delivery, syncChunkStore storage.Sy
128129 maxPeerServers : options .MaxPeerServers ,
129130 balance : balance ,
130131 }
131- //assign the default subscription func: actually do request subscriptions from nodes
132- streamer .subscriptionFunc = streamer .doRequestSubscription
132+
133133 streamer .setupSpec ()
134134
135135 streamer .api = NewAPI (streamer )
@@ -530,15 +530,15 @@ func (r *Registry) requestPeerSubscriptions(kad *network.Kademlia, subs map[enod
530530
531531 for bin := startPo ; bin <= endPo ; bin ++ {
532532 //do the actual subscription
533- ok = r . subscriptionFunc (p , uint8 (bin ), subs )
533+ ok = subscriptionFunc (r , p , uint8 (bin ), subs )
534534 }
535535 return ok
536536 })
537537}
538538
539539// doRequestSubscription sends the actual RequestSubscription to the peer
540- func (r * Registry ) doRequestSubscription ( p * network.Peer , bin uint8 , subs map [enode.ID ]map [Stream ]struct {}) bool {
541- log .Debug (fmt . Sprintf ( "Requesting subscription by: registry %s from peer %s for bin: %d" , r .addr , p .ID (), bin ) )
540+ func doRequestSubscription (r * Registry , p * network.Peer , bin uint8 , subs map [enode.ID ]map [Stream ]struct {}) bool {
541+ log .Debug ("Requesting subscription by registry:" , "registry" , r .addr , "peer" , p .ID (), " bin" , bin )
542542 // bin is always less then 256 and it is safe to convert it to type uint8
543543 stream := NewStream ("SYNC" , FormatSyncBinKey (bin ), true )
544544 if streams , ok := subs [p .ID ()]; ok {
0 commit comments