Compare commits
	
		
			3 Commits
		
	
	
		
			3971d5ca5d
			...
			debug/chec
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 41ddf1f7cb | |||
| 18c723ee42 | |||
| d4f000466f | 
@@ -29,28 +29,29 @@ type PeerCache struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// urlFormat formats the URL of the peer with the data type API function
 | 
			
		||||
func (p *PeerCache) urlFormat(url string, dt tools.DataType) string {
 | 
			
		||||
func (p *PeerCache) urlFormat(hostUrl string, dt tools.DataType) string {
 | 
			
		||||
	// localhost is replaced by the local peer URL
 | 
			
		||||
	// because localhost must collide on a web request security protocol
 | 
			
		||||
	localhost := ""
 | 
			
		||||
	if strings.Contains(url, "localhost") {
 | 
			
		||||
	if strings.Contains(hostUrl, "localhost") {
 | 
			
		||||
		localhost = "localhost"
 | 
			
		||||
	}
 | 
			
		||||
	if strings.Contains(url, "127.0.0.1") {
 | 
			
		||||
	if strings.Contains(hostUrl, "127.0.0.1") {
 | 
			
		||||
		localhost = "127.0.0.1"
 | 
			
		||||
	}
 | 
			
		||||
	if localhost != "" {
 | 
			
		||||
		r := regexp.MustCompile("(" + localhost + ":[0-9]+)")
 | 
			
		||||
		t := r.FindString(url)
 | 
			
		||||
		t := r.FindString(hostUrl)
 | 
			
		||||
		if t != "" {
 | 
			
		||||
			url = strings.Replace(url, t, dt.API()+":8080/oc", -1)
 | 
			
		||||
			hostUrl = strings.Replace(hostUrl, t, dt.API()+":8080/oc", -1)
 | 
			
		||||
		} else {
 | 
			
		||||
			url = strings.ReplaceAll(url, localhost, dt.API()+":8080/oc")
 | 
			
		||||
			hostUrl = strings.ReplaceAll(hostUrl, localhost, dt.API()+":8080/oc")
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		url = dt.API() + "/" + url
 | 
			
		||||
		hostUrl = hostUrl + "/" + strings.ReplaceAll(dt.API(), "oc-", "")
 | 
			
		||||
	}
 | 
			
		||||
	return url
 | 
			
		||||
	fmt.Println("Host URL : ", hostUrl)
 | 
			
		||||
	return hostUrl
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// checkPeerStatus checks the status of a peer
 | 
			
		||||
@@ -65,9 +66,6 @@ func (p *PeerCache) checkPeerStatus(peerID string, appName string) (*Peer, bool)
 | 
			
		||||
	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
 | 
			
		||||
	fmt.Println("URL peer : ", url)
 | 
			
		||||
	fmt.Println("State : ", state)
 | 
			
		||||
	fmt.Println("Services : ", services)
 | 
			
		||||
	return res.(*Peer), state != tools.DEAD && services[appName] == 0 // Return the peer and its status
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -88,7 +86,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:      p.urlFormat((mypeer.Url)+meth, dt),
 | 
			
		||||
			Url:      p.urlFormat((mypeer.Url), dt) + meth,
 | 
			
		||||
			Body:     body,
 | 
			
		||||
			DataType: dt.EnumIndex(),
 | 
			
		||||
			DataID:   dataID,
 | 
			
		||||
@@ -101,7 +99,7 @@ func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
 | 
			
		||||
			return nil, errors.New("peer not found")
 | 
			
		||||
		}
 | 
			
		||||
		// If the peer is reachable, launch the execution
 | 
			
		||||
		url = p.urlFormat((mypeer.Url)+meth, dt)       // Format the URL
 | 
			
		||||
		url = p.urlFormat((mypeer.Url), dt) + meth       // 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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user