feat: store http api config in selfConnectionUris
This commit is contained in:
parent
8a91b912c0
commit
7ab602ce23
|
@ -24,5 +24,6 @@ type P2PService interface {
|
||||||
UpVote(nodeId *encoding.NodeId) error
|
UpVote(nodeId *encoding.NodeId) error
|
||||||
DownVote(nodeId *encoding.NodeId) error
|
DownVote(nodeId *encoding.NodeId) error
|
||||||
NodeId() *encoding.NodeId
|
NodeId() *encoding.NodeId
|
||||||
|
SelfConnectionUris() []*url.URL
|
||||||
Service
|
Service
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,33 +33,44 @@ var (
|
||||||
const nodeBucketName = "nodes"
|
const nodeBucketName = "nodes"
|
||||||
|
|
||||||
type P2PImpl struct {
|
type P2PImpl struct {
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
nodeKeyPair *ed25519.KeyPairEd25519
|
nodeKeyPair *ed25519.KeyPairEd25519
|
||||||
localNodeID *encoding.NodeId
|
localNodeID *encoding.NodeId
|
||||||
networkID string
|
networkID string
|
||||||
nodesBucket *bolt.Bucket
|
nodesBucket *bolt.Bucket
|
||||||
node interfaces.Node
|
node interfaces.Node
|
||||||
inited bool
|
inited bool
|
||||||
reconnectDelay structs.Map
|
reconnectDelay structs.Map
|
||||||
peers structs.Map
|
peers structs.Map
|
||||||
peersPending structs.Map
|
peersPending structs.Map
|
||||||
|
selfConnectionUris []*url.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewP2P(node interfaces.Node) *P2PImpl {
|
func NewP2P(node interfaces.Node) *P2PImpl {
|
||||||
|
uri, err := url.Parse(fmt.Sprintf("wws://%s/%d", node.Config().HTTP.API.Domain, node.Config().HTTP.API.Port))
|
||||||
|
if err != nil {
|
||||||
|
node.Logger().Fatal("failed to HTTP API URL Config", zap.Error(err))
|
||||||
|
}
|
||||||
|
|
||||||
service := &P2PImpl{
|
service := &P2PImpl{
|
||||||
logger: node.Logger(),
|
logger: node.Logger(),
|
||||||
nodeKeyPair: node.Config().KeyPair,
|
nodeKeyPair: node.Config().KeyPair,
|
||||||
networkID: node.Config().P2P.Network,
|
networkID: node.Config().P2P.Network,
|
||||||
node: node,
|
node: node,
|
||||||
inited: false,
|
inited: false,
|
||||||
reconnectDelay: structs.NewMap(),
|
reconnectDelay: structs.NewMap(),
|
||||||
peers: structs.NewMap(),
|
peers: structs.NewMap(),
|
||||||
peersPending: structs.NewMap(),
|
peersPending: structs.NewMap(),
|
||||||
|
selfConnectionUris: []*url.URL{uri},
|
||||||
}
|
}
|
||||||
|
|
||||||
return service
|
return service
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *P2PImpl) SelfConnectionUris() []*url.URL {
|
||||||
|
return p.selfConnectionUris
|
||||||
|
}
|
||||||
|
|
||||||
func (p *P2PImpl) Node() interfaces.Node {
|
func (p *P2PImpl) Node() interfaces.Node {
|
||||||
return p.node
|
return p.node
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue