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

@ -58,16 +58,26 @@ type AccountType struct {
// Used to report a new instance to main
type ReportInstance struct {
from string
endpoint string
status int
from string
endpoint string
status int
}
// Instance's new min_id value
type RunningInstance struct {
endpoint string
min_id string
status int
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) {
@ -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)
go StartInstancePoll(endpoint, "", reportPostChan, pollMessageChan, reportInstanceChan)
// fmt.Println("Temporarily disabled Peer Hunting")
// go StartGetPeers(endpoint, reportInstanceChan)
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) {