diff options
author | David Doan <daviddoan@Davids-MacBook-Pro-70.local> | 2023-10-19 15:59:49 -0400 |
---|---|---|
committer | David Doan <daviddoan@Davids-MacBook-Pro-70.local> | 2023-10-19 15:59:49 -0400 |
commit | 1e66c42543ddbd610968a73b30f8646f289da07a (patch) | |
tree | 7cc595addd16a9e8c007752bfc017a5aac68c0c5 /cmd | |
parent | 1e1f56b0dfe1b95d181ff40eeac0cc4260c937fb (diff) |
RIP
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/vhost/main.go | 15 | ||||
-rw-r--r-- | cmd/vrouter/main.go | 59 |
2 files changed, 49 insertions, 25 deletions
diff --git a/cmd/vhost/main.go b/cmd/vhost/main.go index 27e073f..2ecbfa7 100644 --- a/cmd/vhost/main.go +++ b/cmd/vhost/main.go @@ -65,11 +65,20 @@ func main() { fmt.Println(err) continue } - ipstack.SendIP(ipstack.GetMyVIP(), iface, 0, messageToSendBytes, ipAddr) + err = ipstack.SendIP(ipstack.GetMyVIP(), iface, 0, messageToSendBytes, ipAddr) + if err != nil { + fmt.Println(err) + continue + } + continue + } + err = ipstack.SendIP(ipstack.GetMyVIP(), iface, 0, messageToSendBytes, ipAddr) + if err != nil { + fmt.Println(err) + continue } - ipstack.SendIP(ipstack.GetMyVIP(), iface, 0, messageToSendBytes, ipAddr) } - } + } if len(line) > 2 { if line[:2] == "up" { // get interface name diff --git a/cmd/vrouter/main.go b/cmd/vrouter/main.go index abd0fc0..89f6e5d 100644 --- a/cmd/vrouter/main.go +++ b/cmd/vrouter/main.go @@ -10,25 +10,25 @@ import ( ) -func SendUpdates() { - myInterfaces := ipstack.GetInterfaces() - myNeighbors := ipstack.GetNeighbors() - for _, iface := range myInterfaces { - // send RIP updates to all neighbors - for _, _ = range myNeighbors { - // iface.udp.Write(neighbor, data) - // iface.RecvSocket.Write(neighbor, data) - // wait for response for 12 seconds - response := make([]byte, 512) - iface.RecvSocket.Read(response) - time.Sleep(12 * time.Second) - if len(response) == 0 { - // ipstack.RemoveNeighbor(neighbor) - } - } - } - time.Sleep(5 * time.Second) -} +// func SendUpdates() { +// myInterfaces := ipstack.GetInterfaces() +// myNeighbors := ipstack.GetNeighbors() +// for _, iface := range myInterfaces { +// // send RIP updates to all neighbors +// for _, _ = range myNeighbors { +// // iface.udp.Write(neighbor, data) +// // iface.RecvSocket.Write(neighbor, data) +// // wait for response for 12 seconds +// response := make([]byte, 512) +// iface.RecvSocket.Read(response) +// time.Sleep(12 * time.Second) +// if len(response) == 0 { +// // ipstack.RemoveNeighbor(neighbor) +// } +// } +// } +// time.Sleep(5 * time.Second) +// } func main() { if len(os.Args) != 2 { @@ -44,8 +44,14 @@ func main() { // myNeighbors := ipstack.GetNeighbors() // myRoutes := ipstack.GetRoutes() - go SendUpdates() + go func() { + for { + ipstack.SendUpdates() + time.Sleep(5 * time.Second) + } + }() + go ipstack.CheckAndUpdateRoutingTable() scanner := bufio.NewScanner(os.Stdin) @@ -90,9 +96,18 @@ func main() { fmt.Println(err) continue } - ipstack.SendIP(ipstack.GetMyVIP(), iface, 0, messageToSendBytes, ipAddr) + err = ipstack.SendIP(ipstack.GetMyVIP(), iface, 0, messageToSendBytes, ipAddr) + if err != nil { + fmt.Println(err) + continue + } + continue + } + err = ipstack.SendIP(ipstack.GetMyVIP(), iface, 0, messageToSendBytes, ipAddr) + if err != nil { + fmt.Println(err) + continue } - ipstack.SendIP(ipstack.GetMyVIP(), iface, 0, messageToSendBytes, ipAddr) } } if len(line) > 2 { |