mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
swarm/network/stream: better comments
This commit is contained in:
parent
433ceb00d8
commit
3facdcb0ec
1 changed files with 22 additions and 9 deletions
|
|
@ -53,15 +53,23 @@ type RetrievalOption int
|
||||||
|
|
||||||
//Syncing options
|
//Syncing options
|
||||||
const (
|
const (
|
||||||
SyncingDisabled SyncingOption = iota //Disable Syncing
|
//Syncing disabled
|
||||||
SyncingRegisterOnly //Register the client but not subscribe
|
SyncingDisabled SyncingOption = iota
|
||||||
SyncingAutoSubscribe //Subscribe automatically
|
//Register the client and the server but not subscribe
|
||||||
|
SyncingRegisterOnly
|
||||||
|
//Both client and server funcs are registered, subscribe sent automatically
|
||||||
|
SyncingAutoSubscribe
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RetrievalDisabled RetrievalOption = iota //Retrieval disabled
|
//Retrieval disabled
|
||||||
RetrievalClientOnly //Clients retrieve only (Light nodes)
|
RetrievalDisabled RetrievalOption = iota
|
||||||
RetrievalEnabled //Enabled
|
//Only the client side of the retrieve request is registered.
|
||||||
|
//(light nodes do not serve retrieve requests)
|
||||||
|
//once the client is registered, subscription to retrieve request stream is always sent
|
||||||
|
RetrievalClientOn
|
||||||
|
//Both client and server funcs are registered, subscribe sent automatically
|
||||||
|
RetrievalEnabled
|
||||||
)
|
)
|
||||||
|
|
||||||
// Registry registry for outgoing and incoming streamer constructors
|
// Registry registry for outgoing and incoming streamer constructors
|
||||||
|
|
@ -77,15 +85,15 @@ type Registry struct {
|
||||||
peers map[enode.ID]*Peer
|
peers map[enode.ID]*Peer
|
||||||
delivery *Delivery
|
delivery *Delivery
|
||||||
intervalsStore state.Store
|
intervalsStore state.Store
|
||||||
autoRetrieval bool
|
autoRetrieval bool //automatically subscribe to retrieve request stream
|
||||||
maxPeerServers int
|
maxPeerServers int
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegistryOptions holds optional values for NewRegistry constructor.
|
// RegistryOptions holds optional values for NewRegistry constructor.
|
||||||
type RegistryOptions struct {
|
type RegistryOptions struct {
|
||||||
SkipCheck bool
|
SkipCheck bool
|
||||||
Syncing SyncingOption
|
Syncing SyncingOption //Defines syncing behavior
|
||||||
Retrieval RetrievalOption
|
Retrieval RetrievalOption //Defines retrieval behavior
|
||||||
SyncUpdateDelay time.Duration
|
SyncUpdateDelay time.Duration
|
||||||
MaxPeerServers int // The limit of servers for each peer in registry
|
MaxPeerServers int // The limit of servers for each peer in registry
|
||||||
}
|
}
|
||||||
|
|
@ -98,6 +106,7 @@ func NewRegistry(localID enode.ID, delivery *Delivery, syncChunkStore storage.Sy
|
||||||
if options.SyncUpdateDelay <= 0 {
|
if options.SyncUpdateDelay <= 0 {
|
||||||
options.SyncUpdateDelay = 15 * time.Second
|
options.SyncUpdateDelay = 15 * time.Second
|
||||||
}
|
}
|
||||||
|
//check if retriaval has been disabled
|
||||||
retrieval := options.Retrieval != RetrievalDisabled
|
retrieval := options.Retrieval != RetrievalDisabled
|
||||||
|
|
||||||
streamer := &Registry{
|
streamer := &Registry{
|
||||||
|
|
@ -114,6 +123,7 @@ func NewRegistry(localID enode.ID, delivery *Delivery, syncChunkStore storage.Sy
|
||||||
streamer.api = NewAPI(streamer)
|
streamer.api = NewAPI(streamer)
|
||||||
delivery.getPeer = streamer.getPeer
|
delivery.getPeer = streamer.getPeer
|
||||||
|
|
||||||
|
//if retrieval is enabled, register the server func, so that retrieve requests will be served (non-light nodes only)
|
||||||
if options.Retrieval == RetrievalEnabled {
|
if options.Retrieval == RetrievalEnabled {
|
||||||
streamer.RegisterServerFunc(swarmChunkServerStreamName, func(_ *Peer, _ string, live bool) (Server, error) {
|
streamer.RegisterServerFunc(swarmChunkServerStreamName, func(_ *Peer, _ string, live bool) (Server, error) {
|
||||||
if !live {
|
if !live {
|
||||||
|
|
@ -123,17 +133,20 @@ func NewRegistry(localID enode.ID, delivery *Delivery, syncChunkStore storage.Sy
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if retrieval is not disabled, register the client func (both light nodes and normal nodes can issue retrieve requests)
|
||||||
if options.Retrieval != RetrievalDisabled {
|
if options.Retrieval != RetrievalDisabled {
|
||||||
streamer.RegisterClientFunc(swarmChunkServerStreamName, func(p *Peer, t string, live bool) (Client, error) {
|
streamer.RegisterClientFunc(swarmChunkServerStreamName, func(p *Peer, t string, live bool) (Client, error) {
|
||||||
return NewSwarmSyncerClient(p, syncChunkStore, NewStream(swarmChunkServerStreamName, t, live))
|
return NewSwarmSyncerClient(p, syncChunkStore, NewStream(swarmChunkServerStreamName, t, live))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//If syncing is not disabled, the syncing functions are registered (both client and server)
|
||||||
if options.Syncing != SyncingDisabled {
|
if options.Syncing != SyncingDisabled {
|
||||||
RegisterSwarmSyncerServer(streamer, syncChunkStore)
|
RegisterSwarmSyncerServer(streamer, syncChunkStore)
|
||||||
RegisterSwarmSyncerClient(streamer, syncChunkStore)
|
RegisterSwarmSyncerClient(streamer, syncChunkStore)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if syncing is set to automatically subscribe to the syncing stream, start the subscription process
|
||||||
if options.Syncing == SyncingAutoSubscribe {
|
if options.Syncing == SyncingAutoSubscribe {
|
||||||
// latestIntC function ensures that
|
// latestIntC function ensures that
|
||||||
// - receiving from the in chan is not blocked by processing inside the for loop
|
// - receiving from the in chan is not blocked by processing inside the for loop
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue