Check nodeinfo for instance type

This commit is contained in:
farhan 2020-10-28 03:56:24 +00:00
parent afadc4dc39
commit 471b011dc0

View File

@ -66,10 +66,20 @@ type ReportInstance struct {
// Instance's new min_id value // Instance's new min_id value
type RunningInstance struct { type RunningInstance struct {
endpoint string endpoint string
software string
min_id string min_id string
status int 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) { func handleClient(commandClient net.Conn) {
rawCommand := make([]byte, 20) rawCommand := make([]byte, 20)
@ -209,13 +219,26 @@ func DeferPollRun(pollmessage PollMessage, runninginstances *[]RunningInstance,
go StartInstancePoll(pollmessage.from, min_id, reportPostChan, pollMessageChan, reportInstanceChan) 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) { func NewInstance(endpoint string, runninginstances *[]RunningInstance, reportInstanceChan chan ReportInstance, reportPostChan chan ReportPost, pollMessageChan chan PollMessage) {
var nodeinfo NodeInfo
// Check node type // Check node type
GetNodeInfo(endpoint, &nodeinfo)
if endpoint == "" { if endpoint == "" {
return return
@ -225,13 +248,17 @@ func NewInstance(endpoint string, runninginstances *[]RunningInstance, reportIns
return return
} }
} }
newinstance := RunningInstance{endpoint, "", NEW_INSTANCE} newinstance := RunningInstance{endpoint, "", "", NEW_INSTANCE}
*runninginstances = append(*runninginstances, newinstance) *runninginstances = append(*runninginstances, newinstance)
fmt.Println(nodeinfo.Software)
if nodeinfo.Software.Name == "pleroma" || nodeinfo.Software.Name == "mastodon" {
go StartInstancePoll(endpoint, "", reportPostChan, pollMessageChan, reportInstanceChan) go StartInstancePoll(endpoint, "", reportPostChan, pollMessageChan, reportInstanceChan)
// fmt.Println("Temporarily disabled Peer Hunting") // fmt.Println("Temporarily disabled Peer Hunting")
// go StartGetPeers(endpoint, reportInstanceChan) // go StartGetPeers(endpoint, reportInstanceChan)
} }
}
func writePost(pool *pgxpool.Pool, reportpost ReportPost) { func writePost(pool *pgxpool.Pool, reportpost ReportPost) {
conn, err := pool.Acquire(context.Background()) conn, err := pool.Acquire(context.Background())