2019-08-13 21:12:00 +00:00
|
|
|
package p2p
|
|
|
|
|
2020-07-13 04:16:24 +00:00
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
|
|
ma "github.com/multiformats/go-multiaddr"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
2019-08-13 21:12:00 +00:00
|
|
|
|
|
|
|
var log = logrus.WithField("prefix", "p2p")
|
2020-07-13 04:16:24 +00:00
|
|
|
|
|
|
|
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 != "" {
|
2022-08-17 06:38:57 +00:00
|
|
|
multiAddr, err := MultiAddressBuilder(addr, port)
|
2020-07-13 04:16:24 +00:00
|
|
|
if err != nil {
|
2022-08-05 10:52:02 +00:00
|
|
|
log.WithError(err).Error("Could not create multiaddress")
|
2020-07-13 04:16:24 +00:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|