mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
b5bd1260d0
* clean up * clean up * gaz * preston's review * preston's review * Merge refs/heads/master into CleanUpP2P
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package p2p
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
ma "github.com/multiformats/go-multiaddr"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var log = logrus.WithField("prefix", "p2p")
|
|
|
|
func logIPAddr(id peer.ID, addrs ...ma.Multiaddr) {
|
|
var correctAddr ma.Multiaddr
|
|
for _, addr := range addrs {
|
|
if strings.Contains(addr.String(), "/ip4/") || strings.Contains(addr.String(), "/ip6/") {
|
|
correctAddr = addr
|
|
break
|
|
}
|
|
}
|
|
if correctAddr != nil {
|
|
log.WithField(
|
|
"multiAddr",
|
|
correctAddr.String()+"/p2p/"+id.String(),
|
|
).Info("Node started p2p server")
|
|
}
|
|
}
|
|
|
|
func logExternalIPAddr(id peer.ID, addr string, port uint) {
|
|
if addr != "" {
|
|
multiAddr, err := multiAddressBuilder(addr, port)
|
|
if err != nil {
|
|
log.Errorf("Could not create multiaddress: %v", err)
|
|
return
|
|
}
|
|
log.WithField(
|
|
"multiAddr",
|
|
multiAddr.String()+"/p2p/"+id.String(),
|
|
).Info("Node started external p2p server")
|
|
}
|
|
}
|
|
|
|
func logExternalDNSAddr(id peer.ID, addr string, port uint) {
|
|
if addr != "" {
|
|
p := strconv.FormatUint(uint64(port), 10)
|
|
|
|
log.WithField(
|
|
"multiAddr",
|
|
"/dns4/"+addr+"/tcp/"+p+"/p2p/"+id.String(),
|
|
).Info("Node started external p2p server")
|
|
}
|
|
}
|