diff --git a/models/peer/peer.go b/models/peer/peer.go index 745f168..654b2f9 100644 --- a/models/peer/peer.go +++ b/models/peer/peer.go @@ -61,9 +61,12 @@ func (m PeerRelation) EnumIndex() int { type Peer struct { utils.AbstractObject - Verify bool `json:"verify" bson:"verify"` - PeerID string `json:"peer_id" bson:"peer_id" validate:"required"` - Url string `json:"url" bson:"url" validate:"required"` // Url is the URL of the peer (base64url) + Verify bool `json:"verify" bson:"verify"` + PeerID string `json:"peer_id" bson:"peer_id" validate:"required"` + + StreamHost string `json:"stream_host" bson:"stream_host" validate:"required"` // Url is the URL of the peer (base64url) + APIUrl string `json:"api_url" bson:"api_url" validate:"required"` // Url is the URL of the peer (base64url) + NATSUrl string `json:"nats_url" bson:"nats_url" validate:"required"` WalletAddress string `json:"wallet_address" bson:"wallet_address" validate:"required"` // WalletAddress is the wallet address of the peer PublicKey string `json:"public_key" bson:"public_key" validate:"required"` // PublicKey is the public key of the peer diff --git a/models/peer/peer_cache.go b/models/peer/peer_cache.go index 1e999c5..c587f38 100644 --- a/models/peer/peer_cache.go +++ b/models/peer/peer_cache.go @@ -40,7 +40,7 @@ func CheckPeerStatus(peerID string, appName string) (*Peer, bool) { if code != 200 { // no peer no party return nil, false } - url := urlFormat(res.(*Peer).Url, tools.PEER) + "/status" // Format the URL + url := urlFormat(res.(*Peer).APIUrl, tools.PEER) + "/status" // Format the URL state, services := api.CheckRemotePeer(url) res.(*Peer).ServicesState = services // Update the services states of the peer access.UpdateOne(res, peerID) // Update the peer in the db @@ -65,7 +65,7 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string, // If the peer is not reachable, add the execution to the failed executions list pexec := &PeerExecution{ Method: method.String(), - Url: urlFormat((mypeer.Url), dt) + path, // the url is constitued of : host URL + resource path + action path (ex : mypeer.com/datacenter/resourcetype/path/to/action) + Url: urlFormat((mypeer.APIUrl), dt) + path, // the url is constitued of : host URL + resource path + action path (ex : mypeer.com/datacenter/resourcetype/path/to/action) Body: body, DataType: dt.EnumIndex(), DataID: dataID, @@ -78,7 +78,7 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string, return map[string]interface{}{}, errors.New("peer " + peerID + " not found") } // If the peer is reachable, launch the execution - url = urlFormat((mypeer.Url), dt) + path // Format the URL + url = urlFormat((mypeer.APIUrl), dt) + path // Format the URL tmp := mypeer.FailedExecution // Get the failed executions list mypeer.FailedExecution = []PeerExecution{} // Reset the failed executions list NewShallowAccessor().UpdateOne(mypeer, peerID) // Update the peer in the db diff --git a/models/peer/tests/peer_test.go b/models/peer/tests/peer_test.go index 13dfbe5..47eca22 100644 --- a/models/peer/tests/peer_test.go +++ b/models/peer/tests/peer_test.go @@ -48,7 +48,8 @@ func (m *MockAccessor) Search(filters *dbs.Filters, search string, isDraft bool) func newTestPeer() *peer.Peer { return &peer.Peer{ - Url: "http://localhost", + StreamHost: "127.0.0.1", + APIUrl: "http://localhost", WalletAddress: "0x123", PublicKey: "pubkey", Relation: peer.SELF,