aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light/src/core')
-rw-r--r--hicn-light/src/core/connection.c10
-rw-r--r--hicn-light/src/core/connectionTable.c4
-rw-r--r--hicn-light/src/core/dispatcher.c49
-rw-r--r--hicn-light/src/core/dispatcher.h4
-rw-r--r--hicn-light/src/core/forwarder.c32
-rw-r--r--hicn-light/src/core/forwarder.h5
-rw-r--r--hicn-light/src/core/logger.c5
-rw-r--r--hicn-light/src/core/logger.h7
-rw-r--r--hicn-light/src/core/nameBitvector.c16
-rw-r--r--hicn-light/src/core/nameBitvector.h2
-rw-r--r--hicn-light/src/core/wldr.c8
11 files changed, 102 insertions, 40 deletions
diff --git a/hicn-light/src/core/connection.c b/hicn-light/src/core/connection.c
index 073b7260f..505bba081 100644
--- a/hicn-light/src/core/connection.c
+++ b/hicn-light/src/core/connection.c
@@ -193,11 +193,11 @@ bool connection_ReSend(const Connection *conn, Message *message,
// notification
// we need to recompiute the path lable since we always store a pointer to
- // the same message if this message will be sent again to someonelse, the new
- // path label must be computed starting from the orignal labelorignal label.
- // Notice that we heve the same problem in case of PIT aggregation. That case
- // is handled insied the MessageProcessor. This is specific to WLDR
- // retransmittions. This is done only for data packets
+ // the same message if this message will be sent again to someonelse, the
+ // new path label must be computed starting from the orignal labelorignal
+ // label. Notice that we heve the same problem in case of PIT aggregation.
+ // That case is handled insied the MessageProcessor. This is specific to
+ // WLDR retransmittions. This is done only for data packets
if (message_GetType(message) == MessagePacketType_ContentObject) {
uint8_t connectionId = (uint8_t)connection_GetConnectionId(conn);
diff --git a/hicn-light/src/core/connectionTable.c b/hicn-light/src/core/connectionTable.c
index ba0942ddb..8634ec825 100644
--- a/hicn-light/src/core/connectionTable.c
+++ b/hicn-light/src/core/connectionTable.c
@@ -20,11 +20,13 @@
*
*/
+#ifndef _WIN32
+#include <unistd.h>
+#endif
#include <src/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/core/dispatcher.c b/hicn-light/src/core/dispatcher.c
index 078087c59..b6ef5e21f 100644
--- a/hicn-light/src/core/dispatcher.c
+++ b/hicn-light/src/core/dispatcher.c
@@ -22,9 +22,13 @@
* timers, and network events.
*/
+#ifndef _WIN32
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#endif
#include <errno.h>
#include <fcntl.h>
-#include <pthread.h>
#include <signal.h>
#include <src/config.h>
#include <stdarg.h>
@@ -32,10 +36,6 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
-#include <unistd.h>
-
-#include <arpa/inet.h>
-#include <sys/socket.h>
#include <parc/algol/parc_EventQueue.h>
#include <parc/algol/parc_EventTimer.h>
@@ -44,6 +44,8 @@
#include <src/core/dispatcher.h>
+#include <pthread.h>
+
#ifndef INPORT_ANY
#define INPORT_ANY 0
#endif
@@ -298,6 +300,7 @@ static bool dispatcher_StreamBufferBindAndConnect(Dispatcher *dispatcher,
// we need to bind, then connect. Special operation, so we make our
// own fd then pass it off to the buffer event
+#ifndef _WIN32
int fd = socket(localSock->sa_family, SOCK_STREAM, 0);
if (fd < 0) {
perror("socket");
@@ -333,6 +336,42 @@ static bool dispatcher_StreamBufferBindAndConnect(Dispatcher *dispatcher,
close(fd);
return false;
}
+#else
+ SOCKET fd = socket(localSock->sa_family, SOCK_STREAM, 0);
+ if (fd == INVALID_SOCKET) {
+ perror("socket");
+ return -1;
+ }
+
+ // Set non-blocking flag
+ u_long mode = 1;
+ int result = ioctlsocket(fd, FIONBIO, &mode);
+ if (result == NO_ERROR) {
+ perror("ioctlsocket error");
+ closesocket(fd);
+ WSACleanup();
+ return -1;
+ }
+
+ int failure = bind(fd, localSock, (int)localSockLength);
+ if (failure) {
+ perror("bind");
+ closesocket(fd);
+ WSACleanup();
+ return false;
+ }
+
+ parcEventQueue_SetFileDescriptor(buffer, (int)fd);
+
+ failure = parcEventQueue_ConnectSocket(buffer, remoteSock, remoteSockLength);
+ if (failure && (errno != EINPROGRESS)) {
+ perror("connect");
+ closesocket(fd);
+ WSACleanup();
+ return false;
+ }
+#endif
+
return true;
}
diff --git a/hicn-light/src/core/dispatcher.h b/hicn-light/src/core/dispatcher.h
index 35d804a00..96bceb451 100644
--- a/hicn-light/src/core/dispatcher.h
+++ b/hicn-light/src/core/dispatcher.h
@@ -28,8 +28,10 @@
#ifndef dispatcher_h
#define dispatcher_h
-#include <stdbool.h>
+#ifndef _WIN32
#include <sys/socket.h>
+#endif
+#include <stdbool.h>
struct dispatcher;
typedef struct dispatcher Dispatcher;
diff --git a/hicn-light/src/core/forwarder.c b/hicn-light/src/core/forwarder.c
index e84351365..f3af85d6c 100644
--- a/hicn-light/src/core/forwarder.c
+++ b/hicn-light/src/core/forwarder.c
@@ -23,6 +23,11 @@
* the event scheduler
*/
+#ifndef _WIN32
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#endif
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
@@ -32,10 +37,6 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
-#include <unistd.h>
-
-#include <arpa/inet.h>
-#include <sys/socket.h>
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
@@ -80,7 +81,9 @@ struct forwarder {
PARCEventSignal *signal_int;
PARCEventSignal *signal_term;
+#ifndef _WIN32
PARCEventSignal *signal_usr1;
+#endif
PARCEventTimer *keepalive_event;
// will skew the virtual clock forward. In normal operaiton, it is 0.
@@ -121,6 +124,7 @@ static void _keepalive_cb(int, PARCEventType, void *);
* Reseed our pseudo-random number generator.
*/
static void forwarder_Seed(Forwarder *forwarder) {
+#ifndef _WIN32
int fd;
ssize_t res;
@@ -139,6 +143,10 @@ static void forwarder_Seed(Forwarder *forwarder) {
* on other platforms.
*/
seed48(forwarder->seed);
+#else
+ forwarder->seed[1] = (unsigned short)getpid(); /* better than no entropy */
+ forwarder->seed[2] = (unsigned short)time(NULL);
+#endif
}
Logger *forwarder_GetLogger(const Forwarder *forwarder) {
@@ -183,22 +191,25 @@ Forwarder *forwarder_Create(Logger *logger) {
forwarder->signal_int = dispatcher_CreateSignalEvent(
forwarder->dispatcher, _signal_cb, forwarder, SIGINT);
dispatcher_StartSignalEvent(forwarder->dispatcher, forwarder->signal_int);
-
+#ifndef _WIN32
forwarder->signal_usr1 = dispatcher_CreateSignalEvent(
forwarder->dispatcher, _signal_cb, forwarder, SIGPIPE);
dispatcher_StartSignalEvent(forwarder->dispatcher, forwarder->signal_usr1);
+#endif
-#ifndef __APPLE__
+#if !defined(__APPLE__) && !defined(_WIN32)
forwarder->hicnSocketHelper = hicn_create();
if (forwarder->hicnSocketHelper == NULL) return NULL;
#endif /* __APPLE__ */
- /* ignore child */
+ /* ignore child */
+#ifndef _WIN32
signal(SIGCHLD, SIG_IGN);
/* ignore tty signals */
signal(SIGTSTP, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
signal(SIGTTIN, SIG_IGN);
+#endif
// We no longer use this for ticks, but we need to have at least one event
// schedule to keep Libevent happy.
@@ -226,7 +237,7 @@ void forwarder_Destroy(Forwarder **ptr) {
parcAssertNotNull(ptr, "Parameter must be non-null double pointer");
parcAssertNotNull(*ptr, "Parameter must dereference to non-null pointer");
Forwarder *forwarder = *ptr;
-#if !defined(__APPLE__) && !defined(__ANDROID__)
+#if !defined(__APPLE__) && !defined(__ANDROID__) && !defined(_WIN32)
hicn_destroy();
#endif
parcEventTimer_Destroy(&(forwarder->keepalive_event));
@@ -244,8 +255,10 @@ void forwarder_Destroy(Forwarder **ptr) {
&(forwarder->signal_int));
dispatcher_DestroySignalEvent(forwarder->dispatcher,
&(forwarder->signal_term));
+#ifndef _WIN32
dispatcher_DestroySignalEvent(forwarder->dispatcher,
&(forwarder->signal_usr1));
+#endif
parcClock_Release(&forwarder->clock);
logger_Release(&forwarder->logger);
@@ -463,10 +476,11 @@ static void _signal_cb(int sig, PARCEventType events, void *user_data) {
__func__, "Caught an interrupt signal; exiting cleanly.");
dispatcher_Stop(forwarder->dispatcher);
break;
-
+#ifndef _WIN32
case SIGUSR1:
// dump stats
break;
+#endif
default:
break;
diff --git a/hicn-light/src/core/forwarder.h b/hicn-light/src/core/forwarder.h
index e044add3b..6bc823294 100644
--- a/hicn-light/src/core/forwarder.h
+++ b/hicn-light/src/core/forwarder.h
@@ -21,8 +21,10 @@
#ifndef forwarder_h
#define forwarder_h
-#include <stdlib.h>
+#ifndef _WIN32
#include <sys/time.h>
+#endif
+#include <stdlib.h>
#include <src/core/connectionTable.h>
#include <src/core/dispatcher.h>
@@ -56,7 +58,6 @@
struct forwarder;
typedef struct forwarder Forwarder;
-
/**
* @function forwarder_Create
* @abstract Create the forwarder and use the provided logger for diagnostic
diff --git a/hicn-light/src/core/logger.c b/hicn-light/src/core/logger.c
index cac3000e2..ebc8dc5a1 100644
--- a/hicn-light/src/core/logger.c
+++ b/hicn-light/src/core/logger.c
@@ -13,12 +13,15 @@
* limitations under the License.
*/
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
#include <errno.h>
#include <src/config.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
#include <parc/assert/parc_Assert.h>
diff --git a/hicn-light/src/core/logger.h b/hicn-light/src/core/logger.h
index e2ab7e147..c46a87097 100644
--- a/hicn-light/src/core/logger.h
+++ b/hicn-light/src/core/logger.h
@@ -25,13 +25,14 @@
#ifndef logger_h
#define logger_h
+#ifndef _WIN32
+#include <sys/time.h>
+#endif
#include <parc/algol/parc_Buffer.h>
+#include <parc/algol/parc_Clock.h>
#include <parc/logging/parc_LogLevel.h>
#include <parc/logging/parc_LogReporter.h>
#include <stdarg.h>
-#include <sys/time.h>
-
-#include <parc/algol/parc_Clock.h>
struct logger;
typedef struct logger Logger;
diff --git a/hicn-light/src/core/nameBitvector.c b/hicn-light/src/core/nameBitvector.c
index 66f3eae20..c93f63292 100644
--- a/hicn-light/src/core/nameBitvector.c
+++ b/hicn-light/src/core/nameBitvector.c
@@ -49,7 +49,7 @@ struct name_bitvector {
uint8_t IPversion;
};
-NameBitvector *nameBitvector_CreateFromInAddr(uint32_t s_addr, uint8_t len) {
+NameBitvector *nameBitvector_CreateFromInAddr(uint32_t addr, uint8_t len) {
NameBitvector *bitvector = parcMemory_AllocateAndClear(sizeof(NameBitvector));
parcAssertNotNull(bitvector, "parcMemory_AllocateAndClear(%zu) returned NULL",
sizeof(NameBitvector));
@@ -57,10 +57,10 @@ NameBitvector *nameBitvector_CreateFromInAddr(uint32_t s_addr, uint8_t len) {
bitvector->bits[0] = 0;
bitvector->bits[1] = 0;
- uint8_t addr_1 = (s_addr & 0xff000000) >> 24;
- uint8_t addr_2 = (s_addr & 0x00ff0000) >> 16;
- uint8_t addr_3 = (s_addr & 0x0000ff00) >> 8;
- uint8_t addr_4 = (s_addr & 0x000000ff);
+ uint8_t addr_1 = (addr & 0xff000000) >> 24;
+ uint8_t addr_2 = (addr & 0x00ff0000) >> 16;
+ uint8_t addr_3 = (addr & 0x0000ff00) >> 8;
+ uint8_t addr_4 = (addr & 0x000000ff);
bitvector->bits[1] = (bitvector->bits[1] | addr_4) << 8;
bitvector->bits[1] = (bitvector->bits[1] | addr_3) << 8;
@@ -269,9 +269,9 @@ uint8_t nameBitvector_firstDiff(const NameBitvector *a,
// res is computed over the bitvector which is composed by 128 bit all the
// times however the prefixes may be diffrent just because the have different
// lengths example: prefix 1: 0::/30 prefix 2: 0::/20 at this point of the
- // function res would be 0 since both the bitvectors are composed by 0s but the
- // function will return 127-20, which is the position at which the two prefix
- // are different, since prefix 2 has only 20 bits
+ // function res would be 0 since both the bitvectors are composed by 0s but
+ // the function will return 127-20, which is the position at which the two
+ // prefix are different, since prefix 2 has only 20 bits
uint8_t len_diff;
if (a->len < b->len)
diff --git a/hicn-light/src/core/nameBitvector.h b/hicn-light/src/core/nameBitvector.h
index 28a31dc26..fb94f8f1a 100644
--- a/hicn-light/src/core/nameBitvector.h
+++ b/hicn-light/src/core/nameBitvector.h
@@ -25,7 +25,7 @@
struct name_bitvector;
typedef struct name_bitvector NameBitvector;
-NameBitvector *nameBitvector_CreateFromInAddr(uint32_t s_addr, uint8_t len);
+NameBitvector *nameBitvector_CreateFromInAddr(uint32_t addr, uint8_t len);
NameBitvector *nameBitvector_CreateFromIn6Addr(struct in6_addr *addr,
uint8_t len);
diff --git a/hicn-light/src/core/wldr.c b/hicn-light/src/core/wldr.c
index b94ae76e5..a3e8756dd 100644
--- a/hicn-light/src/core/wldr.c
+++ b/hicn-light/src/core/wldr.c
@@ -108,10 +108,10 @@ static void _wldr_SendWldrNotificaiton(Wldr *wldr, const Connection *conn,
// is identified by the src. if message is a data, we need to send the
// notification message with the content name has a source address in this way
// the message will be trapped by the pounting rules in the next hop We define
- // the notification as an interest message so that the NAT in the send function
- // will set the src address of the local connection. Notice that in this way
- // the notification packet will be dispaced to the right connection at the next
- // hop.
+ // the notification as an interest message so that the NAT in the send
+ // function will set the src address of the local connection. Notice that in
+ // this way the notification packet will be dispaced to the right connection
+ // at the next hop.
Message *notification =
message_CreateWldrNotification(message, expected_lbl, received_lbl);