Select Git revision
autopeering.go
autopeering.go 5.56 KiB
package autopeering
import (
"errors"
"fmt"
"hash/fnv"
"net"
"strconv"
"strings"
"sync"
"github.com/iotaledger/goshimmer/plugins/autopeering/local"
"github.com/iotaledger/goshimmer/plugins/banner"
"github.com/iotaledger/goshimmer/plugins/config"
"github.com/iotaledger/hive.go/autopeering/discover"
"github.com/iotaledger/hive.go/autopeering/peer"
"github.com/iotaledger/hive.go/autopeering/peer/service"
"github.com/iotaledger/hive.go/autopeering/selection"
"github.com/iotaledger/hive.go/autopeering/server"
"github.com/iotaledger/hive.go/crypto/ed25519"
"github.com/iotaledger/hive.go/identity"
"github.com/iotaledger/hive.go/logger"
"github.com/mr-tron/base58"
)
// autopeering constants
const (
ProtocolVersion = 0 // update on protocol changes
NetworkVersion = "v0.2" // update on network changes
)
var (
// ErrParsingMasterNode is returned for an invalid master node.
ErrParsingMasterNode = errors.New("cannot parse master node")
// networkID specifies the autopeering network identifier.
networkID = hash32([]byte(banner.AppVersion + NetworkVersion))
// Conn contains the network connection.
Conn *NetConnMetric
)
var (
// the peer discovery protocol
peerDisc *discover.Protocol
peerDiscOnce sync.Once
// the peer selection protocol
peerSel *selection.Protocol
peerSelOnce sync.Once
// block until the peering server has been started
srvBarrier = struct {
once sync.Once
c chan *server.Server
}{c: make(chan *server.Server, 1)}
)
// NetworkID gets the networkID.
func NetworkID() uint32 {
return networkID
}
// Discovery returns the peer discovery instance.
func Discovery() *discover.Protocol {
peerDiscOnce.Do(createPeerDisc)
return peerDisc
}
// Selection returns the neighbor selection instance.