light modification

This commit is contained in:
mr 2025-01-21 11:11:18 +01:00
parent 0d83885b9b
commit bc12fb53be

View File

@ -57,24 +57,28 @@ func (p *PeerCache) urlFormat(url string, dt tools.DataType) string {
func (p *PeerCache) checkPeerStatus(peerID string, appName string, caller *tools.HTTPCaller) (*Peer, bool) { func (p *PeerCache) checkPeerStatus(peerID string, appName string, caller *tools.HTTPCaller) (*Peer, bool) {
api := tools.API{} api := tools.API{}
access := NewShallowAccessor() access := NewShallowAccessor()
res, code, _ := access.LoadOne(peerID) // Load the peer from db res, code, err := access.LoadOne(peerID) // Load the peer from db
if code != 200 { // no peer no party fmt.Println("Checking peer status", res, code, err)
if code != 200 { // no peer no party
return nil, false return nil, false
} }
methods := caller.URLS[tools.PEER] // Get the methods url of the peer methods := caller.URLS[tools.PEER] // Get the methods url of the peer
fmt.Println("Checking peer status 2", methods)
if methods == nil { if methods == nil {
return res.(*Peer), false return res.(*Peer), false
} }
meth := methods[tools.POST] // Get the POST method to check status meth := methods[tools.POST] // Get the POST method to check status
fmt.Println("Checking peer status 3", meth)
if meth == "" { if meth == "" {
return res.(*Peer), false return res.(*Peer), false
} }
url := p.urlFormat(res.(*Peer).Url, tools.PEER) + meth // Format the URL url := p.urlFormat(res.(*Peer).Url, tools.PEER) + meth // Format the URL
fmt.Println("Checking peer status on", url, "...") fmt.Println("Checking peer status on", url, "...")
state, services := api.CheckRemotePeer(url) state, services := api.CheckRemotePeer(url)
fmt.Println("Checking peer status on", url, state, services) // Check the status of the peer fmt.Println("Checking peer status on", url, state, services) // Check the status of the peer
res.(*Peer).ServicesState = services // Update the services states of the peer res.(*Peer).ServicesState = services // Update the services states of the peer
access.UpdateOne(res, peerID) // Update the peer in the db access.UpdateOne(res, peerID) // Update the peer in the db
fmt.Println("Checking peer status 4", state, state != tools.DEAD, services[appName])
return res.(*Peer), state != tools.DEAD && services[appName] == 0 // Return the peer and its status return res.(*Peer), state != tools.DEAD && services[appName] == 0 // Return the peer and its status
} }