aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/ipstack/ipstack.go27
1 files changed, 13 insertions, 14 deletions
diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go
index 91cc6f9..be8bc1e 100644
--- a/pkg/ipstack/ipstack.go
+++ b/pkg/ipstack/ipstack.go
@@ -20,9 +20,10 @@ const (
// STRUCTS ---------------------------------------------------------------------
type Interface struct {
- Name string
- IpPrefix netip.Prefix
- UdpAddr netip.AddrPort
+ Name string
+ IpPrefix netip.Prefix
+ UdpAddr netip.AddrPort
+
RecvSocket net.UDPConn
SocketChannel chan bool
State bool
@@ -137,7 +138,6 @@ func Initialize(lnxFilePath string) error {
if err != nil {
return errors.WithMessage(err, "Error creating UDP socket for neighbor->\t"+neighbor.DestAddr.String())
}
- // go InterfaceListenerRoutine(n.SendSocket, n.SocketChannel)
myNeighbors[neighbor.InterfaceName] = append(myNeighbors[neighbor.InterfaceName], n)
@@ -150,15 +150,6 @@ func Initialize(lnxFilePath string) error {
return nil
}
-//func InitInterfaceListener(iface *Interface) {
-// // TODO: cleanup syntax
-// iface.State = false
-// go func() {
-// InterfaceListenerRoutine(iface.RecvSocket, iface.SocketChannel)
-// }()
-//}
-
-// TODO: differentiate between SEND AND RECV
func InterfaceListenerRoutine(socket net.UDPConn, signal <-chan bool) {
isUp := false
closed := false
@@ -203,7 +194,6 @@ func InterfaceListenerRoutine(socket net.UDPConn, signal <-chan bool) {
}
}
-// When an interface goes up, we need to start it's go routine that listens
func InterfaceUp(iface *Interface) {
iface.State = true
iface.SocketChannel <- true
@@ -302,6 +292,7 @@ func CleanUp() {
time.Sleep(5 * time.Millisecond)
}
+// TODO: have it take TTL so we can decrement it when forwarding
func SendIP(src Interface, dest Neighbor, protocolNum int, message []byte) error {
hdr := ipv4header.IPv4Header{
Version: 4,
@@ -397,6 +388,14 @@ func RecvIP(conn net.UDPConn, isOpen *bool) error {
fmt.Printf("Received IP packet from %s\nHeader: %v\nChecksum: %s\nMessage: %s\n",
sourceAddr.String(), hdr, checksumState, string(message))
+ // TODO: handle the message
+ // 1) check if the TTL & checksum is valid
+ // 2) check if the message is for me, if so, sendUP (aka call the correct handler)
+ // if not, need to forward the packer to a neighbor or check the table
+ // after decrementing TTL and updating checksum
+ // 3) check if message is for a neighbor, if so, sendIP there
+ // 4) check if message is for a neighbor, if so, forward to the neighbor with that VIP
+
return nil
}