github.com/amazechain/amc@v0.1.3/internal/p2p/log.go (about) 1 package p2p 2 3 import ( 4 amcLog "github.com/amazechain/amc/log" 5 "github.com/libp2p/go-libp2p/core/peer" 6 ma "github.com/multiformats/go-multiaddr" 7 "strconv" 8 "strings" 9 ) 10 11 var log = amcLog.New("prefix", "p2p") 12 13 func logIPAddr(id peer.ID, addrs ...ma.Multiaddr) { 14 var correctAddr ma.Multiaddr 15 for _, addr := range addrs { 16 if strings.Contains(addr.String(), "/ip4/") || strings.Contains(addr.String(), "/ip6/") { 17 correctAddr = addr 18 break 19 } 20 } 21 if correctAddr != nil { 22 log.Info("Node started p2p server", "multiAddr", correctAddr.String()+"/p2p/"+id.String()) 23 } 24 } 25 26 func logExternalIPAddr(id peer.ID, addr string, port int) { 27 if addr != "" { 28 multiAddr, err := MultiAddressBuilder(addr, uint(port)) 29 if err != nil { 30 log.Error("Could not create multiaddress", "err", err) 31 return 32 } 33 log.Info("Node started external p2p server", "multiAddr", multiAddr.String()+"/p2p/"+id.String()) 34 } 35 } 36 37 func logExternalDNSAddr(id peer.ID, addr string, port int) { 38 if addr != "" { 39 p := strconv.FormatUint(uint64(port), 10) 40 log.Info("Node started external p2p server", "multiAddr", "/dns4/"+addr+"/tcp/"+p+"/p2p/"+id.String()) 41 } 42 }