MCPcopy Create free account
hub / github.com/DNAProject/DNA / init

Method init

p2pserver/net/netserver/netserver.go:94–126  ·  view source on GitHub ↗

init initializes attribute of network server

()

Source from the content-addressed store, hash-verified

92
93//init initializes attribute of network server
94func (this *NetServer) init() error {
95 this.base.SetVersion(common.PROTOCOL_VERSION)
96
97 if config.DefConfig.Consensus.EnableConsensus {
98 this.base.SetServices(uint64(common.VERIFY_NODE))
99 } else {
100 this.base.SetServices(uint64(common.SERVICE_NODE))
101 }
102
103 if config.DefConfig.P2PNode.NodePort == 0 {
104 log.Error("[p2p]link port invalid")
105 return errors.New("[p2p]invalid link port")
106 }
107
108 this.base.SetPort(uint16(config.DefConfig.P2PNode.NodePort))
109
110 this.base.SetRelay(true)
111
112 rand.Seed(time.Now().UnixNano())
113 id := rand.Uint64()
114
115 this.base.SetID(id)
116
117 log.Infof("[p2p]init peer ID to %d", this.base.GetID())
118 this.Np = &peer.NbrPeers{}
119 this.Np.Init()
120
121 this.connectingNodes.ConnectingAddrs = set.NewStringSet()
122 this.inConnRecord.InConnectingAddrs = set.NewStringSet()
123 this.outConnRecord.OutConnectingAddrs = set.NewStringSet()
124
125 return nil
126}
127
128//InitListen start listening on the config port
129func (this *NetServer) Start() {

Callers 1

NewNetServerFunction · 0.95

Calls 10

ErrorFunction · 0.92
InfofFunction · 0.92
NewStringSetFunction · 0.92
SetVersionMethod · 0.80
SetServicesMethod · 0.80
SetRelayMethod · 0.80
GetIDMethod · 0.65
SetPortMethod · 0.45
SetIDMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected