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

Method startNetAccept

p2pserver/net/netserver/netserver.go:372–427  ·  view source on GitHub ↗

startNetAccept accepts the sync connection from the inbound peer

(listener net.Listener)

Source from the content-addressed store, hash-verified

370
371//startNetAccept accepts the sync connection from the inbound peer
372func (this *NetServer) startNetAccept(listener net.Listener) {
373 for {
374 conn, err := listener.Accept()
375
376 if err != nil {
377 log.Error("[p2p]error accepting ", err.Error())
378 return
379 }
380
381 log.Debug("[p2p]remote sync node connect with ",
382 conn.RemoteAddr(), conn.LocalAddr())
383 if !this.AddrValid(conn.RemoteAddr().String()) {
384 log.Warnf("[p2p]remote %s not in reserved list, close it ", conn.RemoteAddr())
385 conn.Close()
386 continue
387 }
388
389 if this.IsAddrInInConnRecord(conn.RemoteAddr().String()) {
390 conn.Close()
391 continue
392 }
393
394 syncAddrCount := uint(this.GetInConnRecordLen())
395 if syncAddrCount >= config.DefConfig.P2PNode.MaxConnInBound {
396 log.Warnf("[p2p]SyncAccept: total connections(%d) reach the max limit(%d), conn closed",
397 syncAddrCount, config.DefConfig.P2PNode.MaxConnInBound)
398 conn.Close()
399 continue
400 }
401
402 remoteIp, err := common.ParseIPAddr(conn.RemoteAddr().String())
403 if err != nil {
404 log.Warn("[p2p]parse ip error ", err.Error())
405 conn.Close()
406 continue
407 }
408 connNum := this.GetIpCountInInConnRecord(remoteIp)
409 if connNum >= config.DefConfig.P2PNode.MaxConnInBoundForSingleIP {
410 log.Warnf("[p2p]SyncAccept: connections(%d) with ip(%s) has reach the max limit(%d), "+
411 "conn closed", connNum, remoteIp, config.DefConfig.P2PNode.MaxConnInBoundForSingleIP)
412 conn.Close()
413 continue
414 }
415
416 remotePeer := peer.NewPeer()
417 addr := conn.RemoteAddr().String()
418 this.AddInConnRecord(addr)
419
420 this.AddPeerAddress(addr, remotePeer)
421
422 remotePeer.Link.SetAddr(addr)
423 remotePeer.Link.SetConn(conn)
424 remotePeer.AttachChan(this.NetChan)
425 go remotePeer.Link.Rx()
426 }
427}
428
429//record the peer which is going to be dialed and sent version message but not in establish state

Callers 1

startNetListeningMethod · 0.95

Calls 15

AddrValidMethod · 0.95
IsAddrInInConnRecordMethod · 0.95
GetInConnRecordLenMethod · 0.95
AddInConnRecordMethod · 0.95
AddPeerAddressMethod · 0.95
AttachChanMethod · 0.95
ErrorFunction · 0.92
DebugFunction · 0.92
WarnfFunction · 0.92
ParseIPAddrFunction · 0.92
WarnFunction · 0.92

Tested by

no test coverage detected