init initializes attribute of network server
()
| 92 | |
| 93 | //init initializes attribute of network server |
| 94 | func (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 |
| 129 | func (this *NetServer) Start() { |
no test coverage detected