feat: store http api config in selfConnectionUris

This commit is contained in:
Derrick Hammer 2024-01-10 09:36:55 -05:00
parent 8a91b912c0
commit 7ab602ce23
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 30 additions and 18 deletions

View File

@ -24,5 +24,6 @@ type P2PService interface {
UpVote(nodeId *encoding.NodeId) error
DownVote(nodeId *encoding.NodeId) error
NodeId() *encoding.NodeId
SelfConnectionUris() []*url.URL
Service
}

View File

@ -43,9 +43,15 @@ type P2PImpl struct {
reconnectDelay structs.Map
peers structs.Map
peersPending structs.Map
selfConnectionUris []*url.URL
}
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{
logger: node.Logger(),
nodeKeyPair: node.Config().KeyPair,
@ -55,11 +61,16 @@ func NewP2P(node interfaces.Node) *P2PImpl {
reconnectDelay: structs.NewMap(),
peers: structs.NewMap(),
peersPending: structs.NewMap(),
selfConnectionUris: []*url.URL{uri},
}
return service
}
func (p *P2PImpl) SelfConnectionUris() []*url.URL {
return p.selfConnectionUris
}
func (p *P2PImpl) Node() interfaces.Node {
return p.node
}