152 lines
3.3 KiB
Go
152 lines
3.3 KiB
Go
package main
|
|
|
|
import "fmt"
|
|
import "log"
|
|
import "net"
|
|
import "os"
|
|
import "io"
|
|
import "bytes"
|
|
import "strconv"
|
|
|
|
import "github.com/golang/protobuf/proto"
|
|
import pb "git.wit.com/wit/witProtobuf"
|
|
|
|
import "git.wit.com/wit/gui"
|
|
|
|
var mychannel chan *pb.Event
|
|
|
|
func initChannel() {
|
|
mychannel = make(chan *pb.Event)
|
|
}
|
|
|
|
// func processEvents(mychannel chan *pb.Event) {
|
|
func processEvents() {
|
|
for {
|
|
message := <-mychannel
|
|
log.Println("processEvents() on channel recieved a message = ", message)
|
|
mh := addVmsTab(30)
|
|
ReadReceivedData(message, mh)
|
|
if (message.Type == pb.Event_DEMO) {
|
|
log.Println("processEvents() do Event DEMO")
|
|
}
|
|
}
|
|
}
|
|
|
|
func ReadReceivedData(data *pb.Event, mh *gui.TableData) {
|
|
msgItems := data.GetResults()
|
|
log.Println("ReadReceivedData() Event msgItems=", msgItems)
|
|
for _, item := range msgItems {
|
|
log.Println(item)
|
|
}
|
|
|
|
nets := data.GetNetworks()
|
|
log.Println("ReadReceivedData() Event networks=", nets)
|
|
for _, item := range nets {
|
|
log.Println(item)
|
|
}
|
|
|
|
vms := data.GetVms()
|
|
log.Println("ReadReceivedData() Event vms=", vms)
|
|
row := 0
|
|
for _, item := range vms {
|
|
mh.Rows[row].HumanData[3].Text = item.Name
|
|
log.Println(item)
|
|
row += 1
|
|
}
|
|
|
|
log.Println("ReadReceivedData() mh rows")
|
|
for row := 0; row < mh.RowCount; row++ {
|
|
log.Println("\trow=", row)
|
|
}
|
|
}
|
|
|
|
func handleProtoClient(conn net.Conn) {
|
|
fmt.Println("Connected!")
|
|
defer conn.Close()
|
|
var buf bytes.Buffer
|
|
_, err := io.Copy(&buf, conn)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
|
|
return
|
|
}
|
|
pdata := pb.CreateSampleEvent()
|
|
err = proto.Unmarshal(buf.Bytes(), pdata)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
|
|
return
|
|
}
|
|
mychannel <- pdata
|
|
}
|
|
|
|
// Marshal & Unmarshal just to see if it ever fails
|
|
func addEvent(msg *pb.Event) {
|
|
data, err := proto.Marshal(msg)
|
|
if (err != nil) {
|
|
log.Printf("addEvent() something fucked up happened in Marshal")
|
|
}
|
|
|
|
pdata := new(pb.Event)
|
|
err = proto.Unmarshal(data, pdata)
|
|
if (err != nil) {
|
|
log.Printf("addEvent() something fucked up happened in Unmarshal")
|
|
}
|
|
|
|
mychannel <- pdata
|
|
}
|
|
|
|
func addSampleEvent() {
|
|
msg := pb.CreateSampleEvent()
|
|
msg.Name = "generated in addSampleEvent()"
|
|
|
|
data, err := proto.Marshal(msg)
|
|
if (err != nil) {
|
|
log.Printf("addSampleEvent() something fucked up happened in Marshal")
|
|
}
|
|
|
|
pdata := new(pb.Event)
|
|
err = proto.Unmarshal(data, pdata)
|
|
if (err != nil) {
|
|
log.Printf("addSampleEvent() something fucked up happened in Unmarshal")
|
|
}
|
|
|
|
mychannel <- pdata
|
|
}
|
|
|
|
func sendEventToWIT() {
|
|
msg := pb.CreateSampleEvent()
|
|
|
|
var mybuf []byte
|
|
mybuf, err := proto.Marshal(msg)
|
|
if (err != nil) {
|
|
log.Printf("something fucked up happened")
|
|
}
|
|
writeBytesToSocket(mybuf)
|
|
}
|
|
|
|
func sendDataToDest() {
|
|
msg := pb.CreateSampleEvent()
|
|
msg.Name = "from dnssecsockettest()"
|
|
|
|
data, err := proto.Marshal(msg)
|
|
if (err != nil) {
|
|
log.Printf("something fucked up happened")
|
|
}
|
|
|
|
conn, err := net.Dial("tcp", "localhost:8080")
|
|
if err != nil {
|
|
log.Println("Fatal error: %s", err.Error())
|
|
return
|
|
}
|
|
n, err := conn.Write(data)
|
|
if err != nil {
|
|
// fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
|
|
log.Println("Fatal error: %s", err.Error())
|
|
return
|
|
}
|
|
|
|
pb.DumpEventData(msg)
|
|
log.Println("Sent " + strconv.Itoa(n) + " bytes")
|
|
// time.Sleep(3 * 1000 * 1000 * 1000)
|
|
conn.Close()
|
|
}
|