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

Function createAddrBookAndSetOnSwitch

node/node.go:600–625  ·  view source on GitHub ↗
(config *cfg.Config, sw *p2p.Switch,
	p2pLogger log.Logger, nodeKey *p2p.NodeKey,
)

Source from the content-addressed store, hash-verified

598}
599
600func createAddrBookAndSetOnSwitch(config *cfg.Config, sw *p2p.Switch,
601 p2pLogger log.Logger, nodeKey *p2p.NodeKey,
602) (pex.AddrBook, error) {
603 addrBook := pex.NewAddrBook(config.P2P.AddrBookFile(), config.P2P.AddrBookStrict)
604 addrBook.SetLogger(p2pLogger.With("book", config.P2P.AddrBookFile()))
605
606 // Add ourselves to addrbook to prevent dialing ourselves
607 if config.P2P.ExternalAddress != "" {
608 addr, err := p2p.NewNetAddressString(p2p.IDAddressString(nodeKey.ID(), config.P2P.ExternalAddress))
609 if err != nil {
610 return nil, fmt.Errorf("p2p.external_address is incorrect: %w", err)
611 }
612 addrBook.AddOurAddress(addr)
613 }
614 if config.P2P.ListenAddress != "" {
615 addr, err := p2p.NewNetAddressString(p2p.IDAddressString(nodeKey.ID(), config.P2P.ListenAddress))
616 if err != nil {
617 return nil, fmt.Errorf("p2p.laddr is incorrect: %w", err)
618 }
619 addrBook.AddOurAddress(addr)
620 }
621
622 sw.SetAddrBook(addrBook)
623
624 return addrBook, nil
625}
626
627func createPEXReactorAndAddToSwitch(addrBook pex.AddrBook, config *cfg.Config,
628 sw *p2p.Switch, logger log.Logger,

Callers 1

NewNodeFunction · 0.70

Calls 9

AddOurAddressMethod · 0.95
NewAddrBookFunction · 0.92
NewNetAddressStringFunction · 0.92
IDAddressStringFunction · 0.92
AddrBookFileMethod · 0.80
SetAddrBookMethod · 0.80
SetLoggerMethod · 0.65
WithMethod · 0.65
IDMethod · 0.65

Tested by

no test coverage detected