MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / CustomReactors

Function CustomReactors

node/node.go:155–181  ·  view source on GitHub ↗

CustomReactors allows you to add custom reactors (name -> p2p.Reactor) to the node's Switch. WARNING: using any name from the below list of the existing reactors will result in replacing it with the custom one. - MEMPOOL - BLOCKCHAIN - CONSENSUS - EVIDENCE - PEX - STATESYNC

(reactors map[string]p2p.Reactor)

Source from the content-addressed store, hash-verified

153// - PEX
154// - STATESYNC
155func CustomReactors(reactors map[string]p2p.Reactor) Option {
156 return func(n *Node) {
157 for name, reactor := range reactors {
158 if existingReactor := n.sw.Reactor(name); existingReactor != nil {
159 n.sw.Logger.Info("Replacing existing reactor with a custom one",
160 "name", name, "existing", existingReactor, "custom", reactor)
161 n.sw.RemoveReactor(name, existingReactor)
162 }
163 n.sw.AddReactor(name, reactor)
164 // register the new channels to the nodeInfo
165 // NOTE: This is a bit messy now with the type casting but is
166 // cleaned up in the following version when NodeInfo is changed from
167 // and interface to a concrete type
168 if ni, ok := n.nodeInfo.(p2p.DefaultNodeInfo); ok {
169 for _, chDesc := range reactor.GetChannels() {
170 if !ni.HasChannel(chDesc.ID) {
171 ni.Channels = append(ni.Channels, chDesc.ID)
172 n.transport.AddChannel(chDesc.ID)
173 }
174 }
175 n.nodeInfo = ni
176 } else {
177 n.Logger.Error("Node info is not of type DefaultNodeInfo. Custom reactor channels can not be added.")
178 }
179 }
180 }
181}
182
183// StateProvider overrides the state provider used by state sync to retrieve trusted app hashes and
184// build a State object for bootstrapping the node.

Callers 1

Calls 8

ReactorMethod · 0.80
RemoveReactorMethod · 0.80
AddReactorMethod · 0.80
HasChannelMethod · 0.80
AddChannelMethod · 0.80
InfoMethod · 0.65
GetChannelsMethod · 0.65
ErrorMethod · 0.65

Tested by 1