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

Function MakeSwitch

p2p/test_util.go:178–220  ·  view source on GitHub ↗
(
	cfg *config.P2PConfig,
	i int,
	network, version string,
	initSwitch func(int, *Switch) *Switch,
	opts ...SwitchOption,
)

Source from the content-addressed store, hash-verified

176}
177
178func MakeSwitch(
179 cfg *config.P2PConfig,
180 i int,
181 network, version string,
182 initSwitch func(int, *Switch) *Switch,
183 opts ...SwitchOption,
184) *Switch {
185
186 nodeKey := NodeKey{
187 PrivKey: ed25519.GenPrivKey(),
188 }
189 nodeInfo := testNodeInfo(nodeKey.ID(), fmt.Sprintf("node%d", i))
190 addr, err := NewNetAddressString(
191 IDAddressString(nodeKey.ID(), nodeInfo.(DefaultNodeInfo).ListenAddr),
192 )
193 if err != nil {
194 panic(err)
195 }
196
197 t := NewMultiplexTransport(nodeInfo, nodeKey, MConnConfig(cfg))
198
199 if err := t.Listen(*addr); err != nil {
200 panic(err)
201 }
202
203 // TODO: let the config be passed in?
204 sw := initSwitch(i, NewSwitch(cfg, t, opts...))
205 sw.SetLogger(log.TestingLogger().With("switch", i))
206 sw.SetNodeKey(&nodeKey)
207
208 ni := nodeInfo.(DefaultNodeInfo)
209 for ch := range sw.reactorsByCh {
210 ni.Channels = append(ni.Channels, ch)
211 }
212 nodeInfo = ni
213
214 // TODO: We need to setup reactors ahead of time so the NodeInfo is properly
215 // populated and we don't have to do those awkward overrides and setters.
216 t.nodeInfo = nodeInfo
217 sw.SetNodeInfo(nodeInfo)
218
219 return sw
220}
221
222func testInboundPeerConn(
223 conn net.Conn,

Calls 14

IDMethod · 0.95
ListenMethod · 0.95
GenPrivKeyFunction · 0.92
TestingLoggerFunction · 0.92
testNodeInfoFunction · 0.85
NewNetAddressStringFunction · 0.85
IDAddressStringFunction · 0.85
NewMultiplexTransportFunction · 0.85
NewSwitchFunction · 0.85
SetNodeKeyMethod · 0.80
SetNodeInfoMethod · 0.80
MConnConfigFunction · 0.70