Check nodeinfo for instance type
This commit is contained in:
parent
afadc4dc39
commit
471b011dc0
@ -58,16 +58,26 @@ type AccountType struct {
|
|||||||
|
|
||||||
// Used to report a new instance to main
|
// Used to report a new instance to main
|
||||||
type ReportInstance struct {
|
type ReportInstance struct {
|
||||||
from string
|
from string
|
||||||
endpoint string
|
endpoint string
|
||||||
status int
|
status int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Instance's new min_id value
|
// Instance's new min_id value
|
||||||
type RunningInstance struct {
|
type RunningInstance struct {
|
||||||
endpoint string
|
endpoint string
|
||||||
min_id string
|
software string
|
||||||
status int
|
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) {
|
func handleClient(commandClient net.Conn) {
|
||||||
@ -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,12 +248,16 @@ 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)
|
||||||
|
|
||||||
go StartInstancePoll(endpoint, "", reportPostChan, pollMessageChan, reportInstanceChan)
|
fmt.Println(nodeinfo.Software)
|
||||||
// fmt.Println("Temporarily disabled Peer Hunting")
|
|
||||||
// go StartGetPeers(endpoint, reportInstanceChan)
|
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) {
|
func writePost(pool *pgxpool.Pool, reportpost ReportPost) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user