Check nodeinfo for instance type
This commit is contained in:
parent
afadc4dc39
commit
471b011dc0
@ -66,10 +66,20 @@ type ReportInstance struct {
|
||||
// Instance's new min_id value
|
||||
type RunningInstance struct {
|
||||
endpoint string
|
||||
software string
|
||||
min_id string
|
||||
status int
|
||||
}
|
||||
|
||||
type NodeInfoSoftware struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
type NodeInfo struct {
|
||||
Software NodeInfoSoftware `json:"software"`
|
||||
}
|
||||
|
||||
func handleClient(commandClient net.Conn) {
|
||||
rawCommand := make([]byte, 20)
|
||||
|
||||
@ -209,13 +219,26 @@ func DeferPollRun(pollmessage PollMessage, runninginstances *[]RunningInstance,
|
||||
go StartInstancePoll(pollmessage.from, min_id, reportPostChan, pollMessageChan, reportInstanceChan)
|
||||
}
|
||||
|
||||
func GetNodeInfo(endpoint string) {
|
||||
// Change this to return a proper "err"
|
||||
func GetNodeInfo(endpoint string, nodeinfo *NodeInfo) {
|
||||
api_nodeinfo := "https://" + endpoint + "/nodeinfo/2.0.json"
|
||||
resp, err := http.Get(api_nodeinfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
err = json.Unmarshal(body, &nodeinfo)
|
||||
fmt.Println("Body: " + string(body))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func NewInstance(endpoint string, runninginstances *[]RunningInstance, reportInstanceChan chan ReportInstance, reportPostChan chan ReportPost, pollMessageChan chan PollMessage) {
|
||||
|
||||
var nodeinfo NodeInfo
|
||||
// Check node type
|
||||
|
||||
GetNodeInfo(endpoint, &nodeinfo)
|
||||
|
||||
if endpoint == "" {
|
||||
return
|
||||
@ -225,12 +248,16 @@ func NewInstance(endpoint string, runninginstances *[]RunningInstance, reportIns
|
||||
return
|
||||
}
|
||||
}
|
||||
newinstance := RunningInstance{endpoint, "", NEW_INSTANCE}
|
||||
newinstance := RunningInstance{endpoint, "", "", NEW_INSTANCE}
|
||||
*runninginstances = append(*runninginstances, newinstance)
|
||||
|
||||
fmt.Println(nodeinfo.Software)
|
||||
|
||||
if nodeinfo.Software.Name == "pleroma" || nodeinfo.Software.Name == "mastodon" {
|
||||
go StartInstancePoll(endpoint, "", reportPostChan, pollMessageChan, reportInstanceChan)
|
||||
// fmt.Println("Temporarily disabled Peer Hunting")
|
||||
// go StartGetPeers(endpoint, reportInstanceChan)
|
||||
}
|
||||
}
|
||||
|
||||
func writePost(pool *pgxpool.Pool, reportpost ReportPost) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user