basic linting

This commit is contained in:
farhan 2020-11-13 20:13:13 -05:00
parent 8a12f277b1
commit 4c51cd861a
5 changed files with 44 additions and 13 deletions

View File

@ -45,11 +45,11 @@ func main() {
var commandMap CommandMap var commandMap CommandMap
var responseback ResponseBack var responseback ResponseBack
if *shutdownPtr == true { if *shutdownPtr {
totalflags++ totalflags++
commandMap.Type = "shutdown" commandMap.Type = "shutdown"
} }
if *statusPtr == true { if *statusPtr {
totalflags++ totalflags++
commandMap.Type = "status" commandMap.Type = "status"
} }
@ -89,8 +89,16 @@ func main() {
// Send the request // Send the request
binary.LittleEndian.PutUint32(sizebytes, uint32(b)) binary.LittleEndian.PutUint32(sizebytes, uint32(b))
c.Write(sizebytes) _, err = c.Write(sizebytes)
c.Write(commandByte) if err != nil {
fmt.Println(err)
return
}
_, err = c.Write(commandByte)
if err != nil {
fmt.Println(err)
return
}
// Read the response // Read the response
n, err := io.ReadFull(c, sizebytes) n, err := io.ReadFull(c, sizebytes)
@ -99,7 +107,10 @@ func main() {
} }
jsonsize := int(binary.LittleEndian.Uint32(sizebytes)) jsonsize := int(binary.LittleEndian.Uint32(sizebytes))
responsebytes := make([]byte, jsonsize) responsebytes := make([]byte, jsonsize)
n, err = io.ReadFull(c, responsebytes) _, err = io.ReadFull(c, responsebytes)
if err != nil {
fmt.Println("Read Error", err)
}
err = json.Unmarshal(responsebytes, &responseback) err = json.Unmarshal(responsebytes, &responseback)
if err != nil { if err != nil {
fmt.Println("Unmarshal error", err) fmt.Println("Unmarshal error", err)

View File

@ -16,6 +16,10 @@ func handleClient(commandClient net.Conn, runninginstances *[]RunningInstance, i
var commandmap CommandMap var commandmap CommandMap
var responseback ResponseBack var responseback ResponseBack
n, err := io.ReadFull(commandClient, sizebyte) n, err := io.ReadFull(commandClient, sizebyte)
if err != nil {
fmt.Println("Read error", err)
os.Exit(1)
}
if n != 4 { if n != 4 {
fmt.Println("Did not read 4 bytes, failure.") fmt.Println("Did not read 4 bytes, failure.")
os.Exit(1) os.Exit(1)
@ -23,8 +27,12 @@ func handleClient(commandClient net.Conn, runninginstances *[]RunningInstance, i
jsonsize := int(binary.LittleEndian.Uint32(sizebyte)) jsonsize := int(binary.LittleEndian.Uint32(sizebyte))
jsonbyte := make([]byte, jsonsize) jsonbyte := make([]byte, jsonsize)
n, err = io.ReadFull(commandClient, jsonbyte) n, err = io.ReadFull(commandClient, jsonbyte)
if err != nil {
fmt.Println("Unable to unmarshal")
os.Exit(1)
}
if n != jsonsize { if n != jsonsize {
fmt.Println("Failued to read json size of ", n) fmt.Println("Failed to read json size of ", n)
os.Exit(1) os.Exit(1)
} }
@ -67,7 +75,11 @@ func handleClient(commandClient net.Conn, runninginstances *[]RunningInstance, i
n = len(responsebytes) n = len(responsebytes)
binary.LittleEndian.PutUint32(sizebyte, uint32(n)) binary.LittleEndian.PutUint32(sizebyte, uint32(n))
commandClient.Write(sizebyte) _, err = commandClient.Write(sizebyte)
if err != nil {
fmt.Println("Error on write:", err)
os.Exit(1)
}
responsebyte, err := json.Marshal(responseback) responsebyte, err := json.Marshal(responseback)
if err != nil { if err != nil {
@ -75,6 +87,10 @@ func handleClient(commandClient net.Conn, runninginstances *[]RunningInstance, i
os.Exit(1) os.Exit(1)
} }
commandClient.Write(responsebyte) _, err = commandClient.Write(responsebyte)
if err != nil {
fmt.Println("Error on write:", err)
os.Exit(1)
}
commandClient.Close() commandClient.Close()
} }

View File

@ -7,7 +7,6 @@ const (
CLIENT_ISSUE = 600 CLIENT_ISSUE = 600
ONION_PROTOCOL = 601 ONION_PROTOCOL = 601
BAD_RESPONSE = 602 BAD_RESPONSE = 602
NO_CONNECTION = 603
BAD_NODEINFO = 604 BAD_NODEINFO = 604
) )

View File

@ -37,7 +37,7 @@ func StartInstancePoll(instancereport InstanceReport, reportPostChan chan Report
// Only placing this here to later have the option of using // Only placing this here to later have the option of using
// an HTTP client via a SOCKS5 Tor proxy // an HTTP client via a SOCKS5 Tor proxy
if strings.Contains(instancereport.endpoint, ".onion") == true { if strings.Contains(instancereport.endpoint, ".onion") {
instanceReportChan <- InstanceReport{instancereport.endpoint, ONION_PROTOCOL, "", 0} instanceReportChan <- InstanceReport{instancereport.endpoint, ONION_PROTOCOL, "", 0}
return return
} }
@ -48,11 +48,13 @@ func StartInstancePoll(instancereport InstanceReport, reportPostChan chan Report
instanceReportChan <- InstanceReport{instancereport.endpoint, CLIENT_ISSUE, "", 0} instanceReportChan <- InstanceReport{instancereport.endpoint, CLIENT_ISSUE, "", 0}
return return
} }
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil {
instanceReportChan <- InstanceReport{instancereport.endpoint, BAD_RESPONSE, "", 0}
return
}
err = json.Unmarshal(body, &newposts) err = json.Unmarshal(body, &newposts)
if err != nil { if err != nil {
// instanceReportChan <- InstanceReport{instancereport.endpoint, resp.StatusCode, "", 0}
instanceReportChan <- InstanceReport{instancereport.endpoint, BAD_RESPONSE, "", 0} instanceReportChan <- InstanceReport{instancereport.endpoint, BAD_RESPONSE, "", 0}
return return
} }
@ -147,7 +149,6 @@ func NewInstance(endpoint string, runninginstances *[]RunningInstance, instanceR
q.endpoint = endpoint q.endpoint = endpoint
q.status = BAD_NODEINFO q.status = BAD_NODEINFO
instanceReportChan <- q instanceReportChan <- q
return
}() }()
} }

View File

@ -90,6 +90,8 @@ func engine() {
} }
defer l.Close() defer l.Close()
x := 0
commandClient := make(chan net.Conn) commandClient := make(chan net.Conn)
go func(l net.Listener) { go func(l net.Listener) {
@ -112,6 +114,8 @@ func engine() {
go writePost(pool, v) go writePost(pool, v)
case w := <-instanceReportChan: // Start or suspend instance case w := <-instanceReportChan: // Start or suspend instance
if w.status == NEW_INSTANCE { if w.status == NEW_INSTANCE {
fmt.Println("The instance: ", x, ", ", len(runninginstances))
x = x + 1
NewInstance(w.endpoint, &runninginstances, instanceReportChan, reportPostChan) NewInstance(w.endpoint, &runninginstances, instanceReportChan, reportPostChan)
} else if w.status == RUNNING || w.status == TOOMANYREQUESTS { } else if w.status == RUNNING || w.status == TOOMANYREQUESTS {
for i, runninginstance := range runninginstances { for i, runninginstance := range runninginstances {