: bharatvaj/forwarder

commit f319d2db40c7184e2c9236001214ce423b6ddd9a
parent e616670e87103baccfda469e0c855c736df26c5a
Author: Bharatvaj H <bharatvajph@gmail.com>
Date: Fri, 26 Apr 2019 19:02:02 +0000

Merge commit 399c089
5 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/include/NetworkController.hpp b/include/NetworkController.hpp
@@ -99,10 +99,13 @@ public:
         }
         Device *d2 = destNetwork->connect(bi->params);
         if (d2 == nullptr) {
+	        fmt::print("Destination not found\n");
+          d.disconnect();
           // TODO ERROR HANDLE
           return;
         }
         Forwarder *forwarder = new Forwarder(&d, d2);
+	forwarder->start();
         forwarders.push_back(forwarder);
       });
       n->listen(nParams);

@@ -110,4 +113,4 @@ public:
   }
 };
 } // namespace wa
-#endif-
\ No newline at end of file
+#endif
diff --git a/include/device/Device.hpp b/include/device/Device.hpp
@@ -6,6 +6,8 @@ namespace wa {
 class Device : public DeviceInfo {
 public:
   Device() {}
+  // disconnects the device from the network
+  virtual void disconnect() {}
   virtual int read(char *message, int bytesToRead) = 0;
   virtual int write(char *message, int bytesToWrite) = 0;
 };
diff --git a/include/device/IPDevice.hpp b/include/device/IPDevice.hpp
@@ -30,6 +30,10 @@ public:
     return ::write(fd, str, bytesToSend);
   }
 
+  void disconnect(){
+    ::close(fd);
+  }
+
   ~IPDevice() { comm_close_socket(fd); }
 };
 } // namespace wa
diff --git a/include/network/Bluetooth.hpp b/include/network/Bluetooth.hpp
@@ -80,8 +80,9 @@ public:
     // connect to server
     int status = ::connect(s, (struct sockaddr *)&addr, sizeof(addr));
     Device *d = (Device *)new BluetoothDevice(s);
-    if (status < 0) {
-      return nullptr;
+    perror("socket");
+    if(status < 0){
+	    return nullptr;
     }
     return d;
   }
diff --git a/include/network/IP.hpp b/include/network/IP.hpp
@@ -106,7 +106,7 @@ public:
     struct sockaddr_in peer;
     socklen_t peerLen = sizeof(peer);
     static int cont;
-    bool isTcp = false;
+    bool isTcp = true;
     xs_SOCKET fd = start_server(isTcp, 2500);
 
     if (fd < 0) {