Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

more work done on the build

  • Loading branch information...
commit fffb92caa871caa9c081f6d3ab601d83760beafc 1 parent 97b7cb9
Caleb James DeLisle authored
Showing with 531 additions and 410 deletions.
  1. +1 −1  admin/test/Admin_test.c
  2. +9 −6 admin/testframework/AdminTestFramework.c
  3. +1 −1  admin/testframework/AdminTestFramework.h
  4. +23 −0 crypto/CryptoAuth.c
  5. +1 −1  crypto/CryptoAuth_benchmark.c
  6. +11 −0 crypto/CryptoAuth_pvt.h
  7. +4 −15 crypto/random/seed/BsdKernArndSysctlRandomSeed.c
  8. +6 −2 crypto/random/seed/BsdKernArndSysctlRandomSeed.h
  9. +0 −9 crypto/random/seed/DevUrandomRandomSeed.c
  10. +6 −2 crypto/random/seed/DevUrandomRandomSeed.h
  11. +0 −9 crypto/random/seed/LinuxRandomUuidSysctlRandomSeed.c
  12. +6 −2 crypto/random/seed/LinuxRandomUuidSysctlRandomSeed.h
  13. +0 −8 crypto/random/seed/ProcSysKernelRandomUuidRandomSeed.c
  14. +6 −2 crypto/random/seed/ProcSysKernelRandomUuidRandomSeed.h
  15. +5 −14 crypto/{test/Exports.h → random/seed/RandomSeedProvider.h}
  16. +0 −12 crypto/random/seed/RtlGenRandomSeed.c
  17. +6 −2 crypto/random/seed/RtlGenRandomSeed.h
  18. +3 −18 crypto/random/seed/SystemRandomSeed.c
  19. +1 −1  crypto/random/test/Random_test.c
  20. +0 −1  crypto/test/CryptoAuth_test.c
  21. +14 −13 crypto/test/CryptoAuth_unit_test.c
  22. +0 −56 crypto/test/Exports.c
  23. +2 −0  dht/dhtcore/NodeStore.c
  24. +1 −1  dht/dhtcore/test/NodeStore_test.c
  25. 0  interface/{ETHInterface_Linux.c → ETHInterface_linux.c}
  26. +4 −2 interface/ICMP6Generator.c
  27. +1 −1  interface/test/FramingInterface_test.c
  28. +5 −4 interface/test/TUNInterface_ipv4_root_test.c
  29. +7 −6 interface/test/TUNInterface_ipv6_root_test.c
  30. +2 −2 interface/test/UDPInterface_communication_test.c
  31. +1 −1  interface/test/UDPInterface_test.c
  32. 0  interface/tuntap/{TUNInterface_Darwin.c → TUNInterface_darwin.c}
  33. 0  interface/tuntap/{TUNInterface_FreeBSD.c → TUNInterface_freebsd.c}
  34. 0  interface/tuntap/{TUNInterface_Linux.c → TUNInterface_linux.c}
  35. 0  interface/tuntap/{TUNInterface_OpenBSD.c → TUNInterface_openbsd.c}
  36. 0  interface/tuntap/{TUNInterface_Illumos.c → TUNInterface_sunos.c}
  37. 0  interface/tuntap/{TUNInterface_Windows.c → TUNInterface_win32.c}
  38. +11 −2 interface/tuntap/windows/test/TAPDevice_root_test.c
  39. +14 −7 interface/tuntap/windows/test/TAPInterface_root_test.c
  40. +11 −45 memory/Allocator.c
  41. +0 −4 memory/Allocator.h
  42. +4 −4 memory/Allocator_pvt.h
  43. +7 −5 net/Ducttape.c
  44. +1 −1  net/test/DefaultInterfaceController_multiIface_test.c
  45. +2 −2 node_build/Tests.js
  46. +96 −26 node_build/builder.js
  47. +33 −6 node_build/make.js
  48. +1 −1  switch/test/LabelSplicer_test.c
  49. +56 −0 test/RootTest.h
  50. +1 −1  test/cjdroute_routerPing_test.c
  51. +3 −3 test/threeNodes_test.c
  52. +2 −2 test/twoNodes_test.c
  53. +64 −8 testcjdroute.c
  54. +2 −2 tunnel/IpTunnel_admin.c
  55. +2 −2 tunnel/test/IpTunnel_test.c
  56. +2 −0  util/Assert.h
  57. +1 −2  util/Bits.h
  58. +32 −0 util/CompileTimeRandom.h
  59. +3 −3 util/Endian.h
  60. +11 −10 util/Gcc.h
  61. +6 −5 util/Identity.h
  62. +1 −1  util/events/libuv/Event.c
  63. +5 −0 util/events/libuv/EventBase.c
  64. +2 −0  util/events/libuv/EventBase_pvt.h
  65. +3 −3 util/events/libuv/Pipe.c
  66. +1 −1  util/events/libuv/Process.c
  67. +1 −1  util/events/libuv/Time.c
  68. +1 −1  util/events/libuv/Timeout.c
  69. +1 −1  util/events/libuv/UDPAddrInterface.c
  70. +1 −1  util/platform/Sockaddr.c
  71. +6 −1 util/platform/libc/strlen.h
  72. +0 −51 util/platform/netdev/NetPlatform_Win32.c
  73. 0  util/platform/netdev/{NetPlatform_Darwin.c → NetPlatform_darwin.c}
  74. 0  util/platform/netdev/{NetPlatform_FreeBSD.c → NetPlatform_freebsd.c}
  75. 0  util/platform/netdev/{NetPlatform_Linux.c → NetPlatform_linux.c}
  76. 0  util/platform/netdev/{NetPlatform_OpenBSD.c → NetPlatform_openbsd.c}
  77. 0  util/platform/netdev/{NetPlatform_Illumos.c → NetPlatform_sunos.c}
  78. 0  util/platform/netdev/{NetPlatform_Windows.c → NetPlatform_win32.c}
  79. +2 −2 util/test/AddrTools_test.c
  80. +2 −2 util/test/AverageRoller_test.c
  81. +1 −1  util/test/Bits_test.c
  82. +2 −2 util/test/Map_test.c
  83. +11 −9 util/test/Process_test.c
View
2  admin/test/Admin_test.c
@@ -53,7 +53,7 @@ static void standardClient(struct Context* ctx)
int main(int argc, char** argv)
{
- struct AdminTestFramework* framework = AdminTestFramework_setUp(argc, argv);
+ struct AdminTestFramework* framework = AdminTestFramework_setUp(argc, argv, "Admin_test");
struct Context ctx = {
.framework = framework
};
View
15 admin/testframework/AdminTestFramework.c
@@ -44,9 +44,12 @@
#include <unistd.h>
#include <stdlib.h>
-static void spawnAngel(char* asClientPipeName, struct EventBase* base, struct Allocator* alloc)
+static void spawnAngel(char* testName,
+ char* asClientPipeName,
+ struct EventBase* base,
+ struct Allocator* alloc)
{
- char* args[] = { "angel", asClientPipeName, NULL };
+ char* args[] = { testName, "angel", asClientPipeName, NULL };
struct Allocator* tempAlloc = Allocator_child(alloc);
char* path = Process_getPath(tempAlloc);
@@ -131,10 +134,10 @@ static void initAngel(struct Pipe* asClientPipe,
* The "core process" pipes all of its inputs back to the originating process
*/
-struct AdminTestFramework* AdminTestFramework_setUp(int argc, char** argv)
+struct AdminTestFramework* AdminTestFramework_setUp(int argc, char** argv, char* testName)
{
- if (argc > 1 && !strcmp("angel", argv[1])) {
- exit(AngelInit_main(argc, argv));
+ if (argc > 2 && !strcmp(testName, argv[1]) && !strcmp("angel", argv[2])) {
+ exit(AngelInit_main(argc-1, &argv[1]));
}
struct Allocator* alloc = MallocAllocator_new(1<<20);
@@ -158,7 +161,7 @@ struct AdminTestFramework* AdminTestFramework_setUp(int argc, char** argv)
asCorePipe->logger = logger;
struct Interface* asCoreIface = FramingInterface_new(65535, &asCorePipe->iface, alloc);
- spawnAngel(asClientPipeName, eventBase, alloc);
+ spawnAngel(testName, asClientPipeName, eventBase, alloc);
Log_info(logger, "Initializing Angel");
initAngel(asClientPipe, asCoreIface, (char*)asCorePipe->name, eventBase, logger, alloc, rand);
View
2  admin/testframework/AdminTestFramework.h
@@ -35,6 +35,6 @@ struct AdminTestFramework
struct Interface* angelInterface;
};
-struct AdminTestFramework* AdminTestFramework_setUp(int argc, char** argv);
+struct AdminTestFramework* AdminTestFramework_setUp(int argc, char** argv, char* testName);
void AdminTestFramework_tearDown(struct AdminTestFramework* framework);
#endif
View
23 crypto/CryptoAuth.c
@@ -1159,3 +1159,26 @@ struct ReplayProtector* CryptoAuth_getReplayProtector(struct Interface* iface)
Identity_cast((struct CryptoAuth_Wrapper*)iface->senderContext);
return &wrapper->replayProtector;
}
+
+// For testing:
+void CryptoAuth_encryptRndNonce(uint8_t nonce[24], struct Message* msg, uint8_t secret[32])
+{
+ encryptRndNonce(nonce, msg, secret);
+}
+
+int CryptoAuth_decryptRndNonce(uint8_t nonce[24], struct Message* msg, uint8_t secret[32])
+{
+ return decryptRndNonce(nonce, msg, secret);
+}
+
+uint8_t CryptoAuth_encryptHandshake(struct Message* message,
+ struct CryptoAuth_Wrapper* wrapper,
+ int setupMessage)
+{
+ return encryptHandshake(message, wrapper, setupMessage);
+}
+
+uint8_t CryptoAuth_receiveMessage(struct Message* received, struct Interface* interface)
+{
+ return receiveMessage(received, interface);
+}
View
2  crypto/CryptoAuth_benchmark.c
@@ -14,7 +14,7 @@
*/
#include "crypto/random/Random.h"
#include "crypto/CryptoAuth.h"
-#include "crypto/test/Exports.h"
+#include "crypto/CryptoAuth_pvt.h"
#include "io/FileWriter.h"
#include "benc/Object.h"
#include "memory/MallocAllocator.h"
View
11 crypto/CryptoAuth_pvt.h
@@ -119,4 +119,15 @@ struct CryptoAuth_Wrapper
Identity
};
+
+uint8_t CryptoAuth_receiveMessage(struct Message* received, struct Interface* interface);
+
+uint8_t CryptoAuth_encryptHandshake(struct Message* message,
+ struct CryptoAuth_Wrapper* wrapper,
+ int setupMessage);
+
+int CryptoAuth_decryptRndNonce(uint8_t nonce[24], struct Message* msg, uint8_t secret[32]);
+
+void CryptoAuth_encryptRndNonce(uint8_t nonce[24], struct Message* msg, uint8_t secret[32]);
+
#endif
View
19 crypto/random/seed/BsdKernArndSysctlRandomSeed.c
@@ -16,19 +16,14 @@
#include "util/Identity.h"
#include "util/Bits.h"
-#ifndef Windows
- #include <unistd.h>
- #include <errno.h>
- #include <sys/types.h>
- #ifndef Illumos
- #include <sys/sysctl.h>
- #endif
-#endif
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
/** Number of times to try each operation. */
#define MAX_TRIES 10
-#ifdef KERN_ARND
static int get(struct RandomSeed* randomSeed, uint64_t output[8])
{
int mib[] = { CTL_KERN, KERN_ARND };
@@ -56,12 +51,6 @@ static int get(struct RandomSeed* randomSeed, uint64_t output[8])
}
return Bits_isZero(output, 64) ? -1 : 0;
}
-#else
-static int get(struct RandomSeed* randomSeed, uint64_t output[8])
-{
- return -1;
-}
-#endif
struct RandomSeed* BsdKernArndSysctlRandomSeed_new(struct Allocator* alloc)
{
View
8 crypto/random/seed/BsdKernArndSysctlRandomSeed.h
@@ -16,10 +16,14 @@
#define BsdKernArndSysctlRandomSeed_H
#include "crypto/random/seed/RandomSeed.h"
+#include "crypto/random/seed/RandomSeedProvider.h"
#include "memory/Allocator.h"
#include "util/Linker.h"
-Linker_require("crypto/random/seed/BsdKernArndSysctlRandomSeed.c")
-struct RandomSeed* BsdKernArndSysctlRandomSeed_new(struct Allocator* alloc);
+#if defined(freebsd) || defined(openbsd)
+ Linker_require("crypto/random/seed/BsdKernArndSysctlRandomSeed.c")
+ struct RandomSeed* BsdKernArndSysctlRandomSeed_new(struct Allocator* alloc);
+ RandomSeedProvider_register(BsdKernArndSysctlRandomSeed_new)
+#endif
#endif
View
9 crypto/random/seed/DevUrandomRandomSeed.c
@@ -16,8 +16,6 @@
#include "util/Identity.h"
#include "util/Bits.h"
-#ifndef Windows
-
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -60,13 +58,6 @@ static int get(struct RandomSeed* randomSeed, uint64_t output[8])
return -1;
}
-#else
-static int get(struct RandomSeed* randomSeed, uint64_t output[8])
-{
- return -1;
-}
-#endif
-
struct RandomSeed* DevUrandomRandomSeed_new(struct Allocator* alloc)
{
return Allocator_clone(alloc, (&(struct RandomSeed) {
View
8 crypto/random/seed/DevUrandomRandomSeed.h
@@ -16,10 +16,14 @@
#define DevUrandomRandomSeed_H
#include "crypto/random/seed/RandomSeed.h"
+#include "crypto/random/seed/RandomSeedProvider.h"
#include "memory/Allocator.h"
#include "util/Linker.h"
-Linker_require("crypto/random/seed/DevUrandomRandomSeed.c")
-struct RandomSeed* DevUrandomRandomSeed_new(struct Allocator* alloc);
+#ifndef win32
+ Linker_require("crypto/random/seed/DevUrandomRandomSeed.c")
+ struct RandomSeed* DevUrandomRandomSeed_new(struct Allocator* alloc);
+ RandomSeedProvider_register(DevUrandomRandomSeed_new)
+#endif
#endif
View
9 crypto/random/seed/LinuxRandomUuidSysctlRandomSeed.c
@@ -17,8 +17,6 @@
#include "util/Bits.h"
#include "util/Hex.h"
-#ifdef Linux
-
#include <unistd.h>
#include <sys/sysctl.h>
@@ -44,13 +42,6 @@ static int get(struct RandomSeed* randomSeed, uint64_t output[8])
return 0;
}
-#else
-static int get(struct RandomSeed* randomSeed, uint64_t output[8])
-{
- return -1;
-}
-#endif
-
struct RandomSeed* LinuxRandomUuidSysctlRandomSeed_new(struct Allocator* alloc)
{
return Allocator_clone(alloc, (&(struct RandomSeed) {
View
8 crypto/random/seed/LinuxRandomUuidSysctlRandomSeed.h
@@ -16,10 +16,14 @@
#define LinuxRandomUuidSysctlRandomSeed_H
#include "crypto/random/seed/RandomSeed.h"
+#include "crypto/random/seed/RandomSeedProvider.h"
#include "memory/Allocator.h"
#include "util/Linker.h"
-Linker_require("crypto/random/seed/LinuxRandomUuidSysctlRandomSeed.c")
-struct RandomSeed* LinuxRandomUuidSysctlRandomSeed_new(struct Allocator* alloc);
+#ifdef linux
+ Linker_require("crypto/random/seed/LinuxRandomUuidSysctlRandomSeed.c")
+ struct RandomSeed* LinuxRandomUuidSysctlRandomSeed_new(struct Allocator* alloc);
+ RandomSeedProvider_register(LinuxRandomUuidSysctlRandomSeed_new)
+#endif
#endif
View
8 crypto/random/seed/ProcSysKernelRandomUuidRandomSeed.c
@@ -26,8 +26,6 @@
/** Number of times to try each operation. */
#define MAX_TRIES 10
-#ifndef Windows
-
static int getUUID(uint64_t output[2])
{
uint8_t buffer[40] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
@@ -91,12 +89,6 @@ static int get(struct RandomSeed* randomSeed, uint64_t output[8])
}
return 0;
}
-#else // Windows
-static int get(struct RandomSeed* randomSeed, uint64_t output[8])
-{
- return -1;
-}
-#endif
struct RandomSeed* ProcSysKernelRandomUuidRandomSeed_new(struct Allocator* alloc)
{
View
8 crypto/random/seed/ProcSysKernelRandomUuidRandomSeed.h
@@ -16,10 +16,14 @@
#define ProcSysKernelRandomUuidRandomSeed_H
#include "crypto/random/seed/RandomSeed.h"
+#include "crypto/random/seed/RandomSeedProvider.h"
#include "memory/Allocator.h"
#include "util/Linker.h"
-Linker_require("crypto/random/seed/ProcSysKernelRandomUuidRandomSeed.c")
-struct RandomSeed* ProcSysKernelRandomUuidRandomSeed_new(struct Allocator* alloc);
+#ifdef linux
+ Linker_require("crypto/random/seed/ProcSysKernelRandomUuidRandomSeed.c")
+ struct RandomSeed* ProcSysKernelRandomUuidRandomSeed_new(struct Allocator* alloc);
+ RandomSeedProvider_register(ProcSysKernelRandomUuidRandomSeed_new)
+#endif
#endif
View
19 crypto/test/Exports.h → crypto/random/seed/RandomSeedProvider.h
@@ -12,22 +12,13 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef Exports_H
-#define Exports_H
+#ifndef RandomSeedProvider_H
+#define RandomSeedProvider_H
-#include <stdint.h>
+<?js file.RandomSeedProvider_providers = []; ?>
-#include "crypto/CryptoAuth.h"
-#include "wire/Message.h"
-#include "util/Linker.h"
-Linker_require("crypto/test/Exports.c")
+#define RandomSeedProvider_register(name) <?js file.RandomSeedProvider_providers.push(#name) ?>
-void Exports_encryptRndNonce(uint8_t nonce[24], struct Message* msg, uint8_t secret[32]);
-
-int Exports_decryptRndNonce(uint8_t nonce[24], struct Message* msg, uint8_t secret[32]);
-
-uint8_t Exports_encryptHandshake(struct Message* message, struct CryptoAuth_Wrapper* wrapper);
-
-void Exports_receiveMessage(struct Message* received, struct Interface* iface);
+#define RandomSeedProvider_list() <?js return file.RandomSeedProvider_providers.join(','); ?>
#endif
View
12 crypto/random/seed/RtlGenRandomSeed.c
@@ -15,7 +15,6 @@
#include "crypto/random/seed/RtlGenRandomSeed.h"
#include "util/Bits.h"
-#ifdef Windows
#include <stdint.h>
#include <windows.h>
@@ -40,17 +39,6 @@ static void init()
RtlGenRandom = (BOOLEAN (APIENTRY *)(void*,ULONG))GetProcAddress(hLib,"SystemFunction036");
}
-#else
-static void init()
-{
-}
-
-static int get(struct RandomSeed* rand, uint64_t buff[8])
-{
- return -1;
-}
-#endif
-
struct RandomSeed* RtlGenRandomSeed_new(struct Allocator* alloc)
{
init();
View
8 crypto/random/seed/RtlGenRandomSeed.h
@@ -16,10 +16,14 @@
#define RtlGenRandomSeed_H
#include "crypto/random/seed/RandomSeed.h"
+#include "crypto/random/seed/RandomSeedProvider.h"
#include "memory/Allocator.h"
#include "util/Linker.h"
-Linker_require("crypto/random/seed/RtlGenRandomSeed.c")
-struct RandomSeed* RtlGenRandomSeed_new(struct Allocator* alloc);
+#ifdef win32
+ Linker_require("crypto/random/seed/RtlGenRandomSeed.c")
+ struct RandomSeed* RtlGenRandomSeed_new(struct Allocator* alloc);
+ RandomSeedProvider_register(RtlGenRandomSeed_new)
+#endif
#endif
View
21 crypto/random/seed/SystemRandomSeed.c
@@ -15,30 +15,15 @@
#include "crypto/random/seed/RandomSeed.h"
#include "util/log/Log.h"
+#include "crypto/random/seed/RandomSeedProvider.h"
#include "crypto/random/seed/RtlGenRandomSeed.h"
#include "crypto/random/seed/BsdKernArndSysctlRandomSeed.h"
#include "crypto/random/seed/DevUrandomRandomSeed.h"
#include "crypto/random/seed/LinuxRandomUuidSysctlRandomSeed.h"
#include "crypto/random/seed/ProcSysKernelRandomUuidRandomSeed.h"
-static RandomSeed_Provider PROVIDERS[] = {
- /** windows */
- RtlGenRandomSeed_new,
-
- /** bsd syscall(KERN_ARND) */
- BsdKernArndSysctlRandomSeed_new,
-
- /** /dev/urandom */
- DevUrandomRandomSeed_new,
-
- /** linux syscall(RANDOM_UUID) */
- LinuxRandomUuidSysctlRandomSeed_new,
-
- /** linux /proc/sys/kernel/random/uuid */
- ProcSysKernelRandomUuidRandomSeed_new
-};
-#define PROVIDERS_COUNT 5
-Assert_compileTime(PROVIDERS_COUNT == (sizeof(PROVIDERS) / sizeof(RandomSeed_Provider)));
+static RandomSeed_Provider PROVIDERS[] = { RandomSeedProvider_list() };
+#define PROVIDERS_COUNT ((int)(sizeof(PROVIDERS) / sizeof(RandomSeed_Provider)))
struct RandomSeed* SystemRandomSeed_new(RandomSeed_Provider* additionalProviders,
int additionalProviderCount,
View
2  crypto/random/test/Random_test.c
@@ -84,7 +84,7 @@ static void test179(struct Allocator* alloc, struct Log* logger)
Random_bytes(rand, buff, 32);
Random_bytes(rand2, buff, 32);
- Assert_true(Bits_memcmp(buff, buff2, 32));
+ Assert_always(Bits_memcmp(buff, buff2, 32));
}
int main()
View
1  crypto/test/CryptoAuth_test.c
@@ -17,7 +17,6 @@
#define string_strlen
#include "crypto/random/Random.h"
#include "crypto/CryptoAuth.h"
-#include "crypto/test/Exports.h"
#include "io/FileWriter.h"
#include "benc/String.h"
#include "memory/MallocAllocator.h"
View
27 crypto/test/CryptoAuth_unit_test.c
@@ -17,11 +17,9 @@
#include "benc/List.h"
#include "benc/String.h"
#include "crypto/CryptoAuth_pvt.h"
-#include "crypto/test/Exports.h"
#include "crypto/random/Random.h"
#include "crypto/random/test/DeterminentRandomSeed.h"
#include "io/FileWriter.h"
-#include "memory/BufferAllocator.h"
#include "memory/MallocAllocator.h"
#include "memory/Allocator.h"
#include "util/platform/libc/string.h"
@@ -60,7 +58,7 @@ static void encryptRndNonceTest()
struct Message m = { .bytes=&buff[32], .length=12, .padding=32};
strcpy((char*) m.bytes, "hello world");
- Exports_encryptRndNonce(nonce, &m, secret);
+ CryptoAuth_encryptRndNonce(nonce, &m, secret);
uint8_t* expected = (uint8_t*) "1391ac5d03ba9f7099bffbb6e6c69d67ae5bd79391a5b94399b293dc";
uint8_t output[57];
@@ -69,7 +67,7 @@ static void encryptRndNonceTest()
//printf("\n%s\n%s\n", (char*) expected, (char*) output);
Assert_always(!Bits_memcmp(expected, output, 56));
- Assert_always(!Exports_decryptRndNonce(nonce, &m, secret));
+ Assert_always(!CryptoAuth_decryptRndNonce(nonce, &m, secret));
Assert_always(m.length == 12 && !Bits_memcmp(m.bytes, "hello world", m.length));
}
@@ -123,7 +121,9 @@ static struct CryptoAuth_Wrapper* setUp(uint8_t* myPrivateKey,
.context = (struct CryptoAuth_pvt*) ca,
.wrappedInterface = iface
}));
- Identity_set(wrapper);
+ #ifdef Identity_CHECK
+ wrapper->Identity_verifier = ((struct CryptoAuth_pvt*)ca)->Identity_verifier;
+ #endif
if (authPassword) {
struct Interface temp = {
@@ -155,7 +155,7 @@ static void testHello(uint8_t* password, uint8_t* expectedOutput)
.bytes = msgBuff + Headers_CryptoAuth_SIZE
};
Bits_memcpyConst(msg.bytes, hello, 12);
- Exports_encryptHandshake(&msg, wrapper);
+ CryptoAuth_encryptHandshake(&msg, wrapper, 0);
uint8_t actual[265];
Assert_always(Hex_encode(actual, 265, outMessage->bytes, outMessage->length) > 0);
@@ -214,7 +214,7 @@ static void receiveHelloWithNoAuth()
wrapper->externalInterface.receiveMessage = receiveMessage;
wrapper->externalInterface.receiverContext = &finalOut;
- Exports_receiveMessage(&incoming, &(struct Interface) { .receiverContext = wrapper } );
+ CryptoAuth_receiveMessage(&incoming, &(struct Interface) { .receiverContext = wrapper } );
Assert_always(finalOut);
Assert_always(finalOut->length == 12);
@@ -253,10 +253,10 @@ static void repeatHello()
Bits_memcpyConst(&msg2, &msg, sizeof(struct Message));
Bits_memcpyConst(msg2.bytes, hello, 12);
- Exports_encryptHandshake(&msg, &wrapper);
+ CryptoAuth_encryptHandshake(&msg, &wrapper, 0);
Bits_memcpyConst(msg2.bytes, hello, 12);
- Exports_encryptHandshake(&msg2, &wrapper);
+ CryptoAuth_encryptHandshake(&msg2, &wrapper, 0);
// Check the nonce
Assert_always(!Bits_memcmp(msg2.bytes, "\0\0\0\1", 4));
@@ -271,9 +271,11 @@ static void repeatHello()
},
.wrappedInterface = &iface
};
- Identity_set(&wrapper2);
+ #ifdef Identity_CHECK
+ wrapper2.Identity_verifier = ((struct CryptoAuth_pvt*)ca)->Identity_verifier;
+ #endif
- Exports_receiveMessage(out, &(struct Interface) { .receiverContext = &wrapper2 } );
+ CryptoAuth_receiveMessage(out, &(struct Interface) { .receiverContext = &wrapper2 } );
Assert_always(finalOut);
Assert_always(finalOut->length == 12);
@@ -312,8 +314,7 @@ int main()
{
testGetUsers();
- struct Allocator* allocator;
- BufferAllocator_STACK(allocator, 512);
+ struct Allocator* allocator = MallocAllocator_new(4096);
eventBase = EventBase_new(allocator);
helloNoAuth();
helloWithAuth();
View
56 crypto/test/Exports.c
@@ -1,56 +0,0 @@
-/* vim: set expandtab ts=4 sw=4: */
-/*
- * You may redistribute this program and/or modify it under the terms of
- * the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-#define CryptoAuth_addUser Export_CryptoAuth_addUser
-#define CryptoAuth_getUser Export_CryptoAuth_getUser
-#define CryptoAuth_new Export_CryptoAuth_new
-#define CryptoAuth_wrapInterface Export_CryptoAuth_wrapInterface
-#define CryptoAuth_setAuth Export_CryptoAuth_setAuth
-#define CryptoAuth_getPublicKey Export_CryptoAuth_getPublicKey
-#define CryptoAuth_getHerPublicKey Export_CryptoAuth_getHerPublicKey
-#define CryptoAuth_getSession Exports_CryptoAuth_getSession
-#define CryptoAuth_reset Exports_CryptoAuth_reset
-#define CryptoAuth_removeUsers Exports_CryptoAuth_removeUsers
-#define CryptoAuth_getState Exports_CryptoAuth_getState
-#define CryptoAuth_getConnectedInterface Exports_CryptoAuth_getConnectedInterface
-#define CryptoAuth_getUsers Exports_CryptoAuth_getUsers
-#define CryptoAuth_getReplayProtector Exports_CryptoAuth_getReplayProtector
-
-#include "crypto/CryptoAuth.c"
-
-/**
- * This is for allowing the unit testing of functions internal to CryptoAuth
- * while still allowing them to be inlined in larger functions.
- */
-
-
-void Exports_encryptRndNonce(uint8_t nonce[24], struct Message* msg, uint8_t secret[32])
-{
- encryptRndNonce(nonce, msg, secret);
-}
-
-int Exports_decryptRndNonce(uint8_t nonce[24], struct Message* msg, uint8_t secret[32])
-{
- return decryptRndNonce(nonce, msg, secret);
-}
-
-uint8_t Exports_encryptHandshake(struct Message* message, struct CryptoAuth_Wrapper* wrapper)
-{
- return encryptHandshake(message, wrapper, 0);
-}
-
-void Exports_receiveMessage(struct Message* received, struct Interface* interface)
-{
- receiveMessage(received, interface);
-}
View
2  dht/dhtcore/NodeStore.c
@@ -169,6 +169,7 @@ static inline struct Node_Link* getLink(struct NodeStore_pvt* store)
static inline void verifyNode(struct Node_Two* node)
{
+#ifdef PARANOIA
struct Node_Link* link;
for (link = node->reversePeers; link; link = link->nextPeer) {
Assert_true(link->linkAddr == (uintptr_t)link);
@@ -191,6 +192,7 @@ static inline void verifyNode(struct Node_Two* node)
Assert_true(rlink);
lastLink = link;
}
+#endif
}
static void verifyLinks(struct NodeStore_pvt* store)
View
2  dht/dhtcore/test/NodeStore_test.c
@@ -55,7 +55,7 @@ static void missingKey()
"'s/^created new key: \\[\\(.\\{32\\}\\)\\(.\\{32\\}\\)\\]$/\"\\1\"\\n\"\\2\",/p' "
"| sed 's/\\([0-9a-f]\\{2\\}\\)/\\\\x\\1/g' > TestKeys.data && "
"mv ./TestKeys.data ./dht/dhtcore/test/\n");
- Assert_true(false);
+ Assert_always(false);
}
View
0  interface/ETHInterface_Linux.c → interface/ETHInterface_linux.c
File renamed without changes
View
6 interface/ICMP6Generator.c
@@ -122,8 +122,10 @@ static uint8_t sendFragmented(struct ICMP6Generator_pvt* ctx,
Message_shift(msg, headersSize, NULL);
// sanity check
- Assert_true(!Bits_memcmp(&msg->bytes[msg->length], nextMessage->bytes, 8));
- uint64_t msgNextPartFirstLong = ((uint64_t*)nextMessage->bytes)[0];
+ #ifdef PARANOIA
+ Assert_true(!Bits_memcmp(&msg->bytes[msg->length], nextMessage->bytes, 8));
+ uint64_t msgNextPartFirstLong = ((uint64_t*)nextMessage->bytes)[0];
+ #endif
// Set the required fields.
// RFC-2460 includes the fragment header in the offset so we have to add another 8 bytes.
View
2  interface/test/FramingInterface_test.c
@@ -53,7 +53,7 @@ int main()
fi->receiverContext = &output;
char* text = "Hello World!";
- Assert_true(12 == strlen(text));
+ Assert_always(12 == strlen(text));
union MessageLength ml = { .length_be = Endian_hostToBigEndian32(12) };
struct Message* msg;
View
9 interface/test/TUNInterface_ipv4_root_test.c
@@ -36,6 +36,7 @@
#include "wire/Ethernet.h"
#include "wire/Headers.h"
#include "util/platform/netdev/NetDev.h"
+#include "test/RootTest.h"
#include <stdlib.h>
@@ -88,13 +89,13 @@ static uint8_t receiveMessageUDP(struct Message* msg, struct Interface* iface)
static void fail(void* ignored)
{
- Assert_true(!"timeout");
+ Assert_always(!"timeout");
}
int main(int argc, char** argv)
{
// TODO: fix TUNConfigurator_addIp4Address() for Illumos, Darwin, BSD.
- #if defined(Illumos) || defined(Darwin) || defined(FreeBSD) || defined(OpenBSD)
+ #if defined(sunos) || defined(darwin) || defined(freebsd)
return 0;
#endif
@@ -110,12 +111,12 @@ int main(int argc, char** argv)
NetDev_addAddress(assignedIfName, addrA, 30, logger, NULL);
struct Sockaddr_storage ss;
- Assert_true(!Sockaddr_parse("0.0.0.0", &ss));
+ Assert_always(!Sockaddr_parse("0.0.0.0", &ss));
struct AddrInterface* udp = UDPAddrInterface_new(base, &ss.addr, alloc, NULL, logger);
struct Sockaddr* dest = Sockaddr_clone(udp->addr, alloc);
uint8_t* addr;
- Assert_true(4 == Sockaddr_getAddress(dest, &addr));
+ Assert_always(4 == Sockaddr_getAddress(dest, &addr));
Bits_memcpy(addr, testAddrB, 4);
struct Message* msg;
View
13 interface/test/TUNInterface_ipv6_root_test.c
@@ -34,11 +34,12 @@
#include "wire/Ethernet.h"
#include "wire/Headers.h"
#include "util/platform/netdev/NetDev.h"
+#include "test/RootTest.h"
#include <unistd.h>
#include <stdlib.h>
-#ifdef Windows
+#ifdef win32
#include <windows.h>
#define sleep(x) Sleep(1000*x)
#endif
@@ -92,7 +93,7 @@ static uint8_t receiveMessageUDP(struct Message* msg, struct Interface* iface)
static void fail(void* ignored)
{
- Assert_true(!"timeout");
+ Assert_always(!"timeout");
}
static struct AddrInterface* setupUDP(struct EventBase* base,
@@ -123,9 +124,9 @@ int main(int argc, char** argv)
NetDev_addAddress(assignedIfName, addrA, 126, logger, NULL);
struct Sockaddr_storage addr;
- Assert_true(!Sockaddr_parse("[fd00::1]", &addr));
+ Assert_always(!Sockaddr_parse("[fd00::1]", &addr));
- #ifdef BSD
+ #ifdef freebsd
// tun is not setup synchronously in bsd but it lets you bind to the tun's
// address anyway.
sleep(1);
@@ -139,11 +140,11 @@ int main(int argc, char** argv)
break;
}
}
- Assert_true(udp);
+ Assert_always(udp);
struct Sockaddr* dest = Sockaddr_clone(udp->addr, alloc);
uint8_t* addrBytes;
- Assert_true(16 == Sockaddr_getAddress(dest, &addrBytes));
+ Assert_always(16 == Sockaddr_getAddress(dest, &addrBytes));
Bits_memcpy(addrBytes, testAddrB, 16);
struct Message* msg;
View
4 interface/test/UDPInterface_communication_test.c
@@ -68,7 +68,7 @@ static uint8_t receiveMessageB(struct Message* msg, struct Interface* iface)
static void fail(void* ignored)
{
- Assert_true(!"timeout");
+ Assert_always(!"timeout");
}
int main(int argc, char** argv)
@@ -84,7 +84,7 @@ int main(int argc, char** argv)
};
struct Sockaddr_storage addr;
- Assert_true(!Sockaddr_parse("127.0.0.1", &addr));
+ Assert_always(!Sockaddr_parse("127.0.0.1", &addr));
struct UDPInterface* udpA = UDPInterface_new(base, &addr.addr, alloc, NULL, logger, &ic);
struct UDPInterface* udpB = UDPInterface_new(base, &addr.addr, alloc, NULL, logger, &ic);
View
2  interface/test/UDPInterface_test.c
@@ -42,7 +42,7 @@ static int registerPeer(struct InterfaceController* ic,
int main(int argc, char** argv)
{
- struct AdminTestFramework* fw = AdminTestFramework_setUp(argc, argv);
+ struct AdminTestFramework* fw = AdminTestFramework_setUp(argc, argv, "UDPInterface_test");
// mock interface controller.
struct InterfaceController ifController = {
View
0  interface/tuntap/TUNInterface_Darwin.c → interface/tuntap/TUNInterface_darwin.c
File renamed without changes
View
0  interface/tuntap/TUNInterface_FreeBSD.c → interface/tuntap/TUNInterface_freebsd.c
File renamed without changes
View
0  interface/tuntap/TUNInterface_Linux.c → interface/tuntap/TUNInterface_linux.c
File renamed without changes
View
0  interface/tuntap/TUNInterface_OpenBSD.c → interface/tuntap/TUNInterface_openbsd.c
File renamed without changes
View
0  interface/tuntap/TUNInterface_Illumos.c → interface/tuntap/TUNInterface_sunos.c
File renamed without changes
View
0  interface/tuntap/TUNInterface_Windows.c → interface/tuntap/TUNInterface_win32.c
File renamed without changes
View
13 interface/tuntap/windows/test/TAPDevice_root_test.c
@@ -12,18 +12,27 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
+#ifndef win32
+int main(int argc, char** argv)
+{
+ return 0;
+}
+#else
#include "memory/Allocator.h"
#include "memory/MallocAllocator.h"
#include "interface/tuntap/windows/TAPDevice.h"
#include "util/Assert.h"
+#include "test/RootTest.h"
#include <stdio.h>
-int main()
+int main(int argc, char** argv)
{
struct Allocator* alloc = MallocAllocator_new(1<<20);
struct TAPDevice* dev = TAPDevice_find(NULL, NULL, alloc);
Assert_always(dev && dev->name && dev->path);
printf("name [%s] path [%s]\n", dev->name, dev->path);
+ return 0;
}
+
+#endif
View
21 interface/tuntap/windows/test/TAPInterface_root_test.c
@@ -12,7 +12,12 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
+#ifndef win32
+int main(int argc, char** argv)
+{
+ return 0;
+}
+#else
#include "interface/tuntap/windows/TAPInterface.h"
#include "interface/tuntap/windows/NDPServer.h"
#include "exception/Except.h"
@@ -35,18 +40,18 @@ static uint8_t receiveMessage(struct Message* msg, struct Interface* iface)
return 0;
}
// ethernet padding.
- Message_shift(msg, -2);
+ Message_shift(msg, -2, NULL);
uint8_t from[13];
uint8_t to[13];
Hex_encode(from, 13, msg->bytes, 6);
- Message_shift(msg, -6);
+ Message_shift(msg, -6, NULL);
Hex_encode(to, 13, msg->bytes, 6);
- Message_shift(msg, -6);
+ Message_shift(msg, -6, NULL);
uint8_t type[5];
Hex_encode(type, 5, msg->bytes, 2);
- Message_shift(msg, -2);
+ Message_shift(msg, -2, NULL);
int subsubtype = -1;
int subtype = -1;
@@ -96,7 +101,7 @@ printf("Test failed\n");
Allocator_free(alloc);
}
-int main()
+int main(int argc, char** argv)
{
printf("init test");
struct Allocator* alloc = MallocAllocator_new(1<<20);
@@ -112,11 +117,13 @@ printf("init test");
ndp->prefixLen = 8;
struct Sockaddr_storage ss;
- Assert_true(!Sockaddr_parse("fd00::1", &ss));
+ Assert_always(!Sockaddr_parse("fd00::1", &ss));
NetDev_addAddress(ifName, &ss.addr, 8, logger, NULL);
Timeout_setTimeout(fail, alloc, 10000, base, alloc);
EventBase_beginLoop(base);
printf("Test ended\n");
+ return 0;
}
+#endif
View
56 memory/Allocator.c
@@ -83,12 +83,12 @@ static inline unsigned long getRealSize(unsigned long requestedSize)
return ((requestedSize + (sizeof(char*) - 1)) & ~(sizeof(char*) - 1)) // align
+ sizeof(struct Allocator_Allocation_pvt)
#ifdef Allocator_USE_CANARIES
- + sizeof(long)
+ + sizeof(unsigned long)
#endif
;
}
-#define END_CANARY(alloc) ((long*) alloc)[ (alloc->size / sizeof(long)) - 1 ]
+#define END_CANARY(alloc) ((unsigned long*) alloc)[ (alloc->pub.size / sizeof(unsigned long)) - 1 ]
static inline void setCanaries(struct Allocator_Allocation_pvt* alloc,
struct Allocator_pvt* context)
@@ -110,8 +110,8 @@ static inline void checkCanaries(struct Allocator_Allocation_pvt* alloc,
} else {
return;
}
- Assert_failure("%s:%d Fatal error: invalid [%s] canary",
- context->fileName, context->pub.lineNum, canary);
+ Assert_failure("%s:%d Fatal error: invalid [%s] canary\n",
+ context->pub.fileName, context->pub.lineNum, canary);
#endif
}
@@ -234,39 +234,6 @@ static void releaseMemory(struct Allocator_pvt* context,
#endif
}
-/**
- * Change the root allocator for a given subtree.
- * @param alloc an allocator.
- *
-static void changeRoot(struct Allocator_pvt* alloc,
- struct Allocator_FirstCtx* root,
- struct Allocator_pvt* first,
- const char* file,
- int line)
-{
- Assert_true(first != alloc);
- if (!first) {
- first = alloc;
- }
- if (alloc->rootAlloc != NULL) {
- alloc->rootAlloc->spaceAvailable += alloc->allocatedHere;
- }
- if (root != NULL) {
- if (root->spaceAvailable < (int64_t)alloc->allocatedHere) {
- failure(alloc, "Out of memory, limit exceeded", file, line);
- }
- root->spaceAvailable -= alloc->allocatedHere;
- }
- alloc->rootAlloc = root;
-
- struct Allocator_pvt* child = alloc->firstChild;
- while (child) {
- struct Allocator_pvt* nextChild = child->nextSibling;
- changeRoot(child, root, first, file, line);
- child = nextChild;
- }
-}
-*/
// disconnect an allocator from it's parent.
static void disconnect(struct Allocator_pvt* context)
{
@@ -303,7 +270,6 @@ static void connect(struct Allocator_pvt* parent,
child->nextSibling = parent->firstChild;
parent->firstChild = child;
child->lastSibling = parent;
- //changeRoot(child, parent->rootAlloc, NULL, file, line);
}
static struct Allocator_pvt* getParent(struct Allocator_pvt* child)
@@ -320,7 +286,7 @@ static struct Allocator_pvt* getParent(struct Allocator_pvt* child)
child = ls;
ls = ls->lastSibling;
}
- Assert_true(0);
+ Assert_always(0);
}
static void freeAllocator(struct Allocator_pvt* context, const char* file, int line);
@@ -346,7 +312,6 @@ void Allocator_onFreeComplete(struct Allocator_OnFreeJob* onFreeJob)
}
if (!context->onFree) {
- //childFreed(context);
// There are no more jobs, release the memory.
freeAllocator(context, context->pub.fileName, context->pub.lineNum);
}
@@ -367,7 +332,7 @@ static void disconnectAdopted(struct Allocator_pvt* parent, struct Allocator_pvt
}
cpp = &cp->next;
}
- Assert_true(found);
+ Assert_always(found);
Assert_true(child->adoptions);
Assert_true(child->adoptions->parents);
@@ -381,7 +346,7 @@ static void disconnectAdopted(struct Allocator_pvt* parent, struct Allocator_pvt
}
cpp = &cp->next;
}
- Assert_true(found);
+ Assert_always(found);
}
/**
@@ -578,8 +543,9 @@ struct Allocator* Allocator__child(struct Allocator* allocator, const char* file
};
Identity_set(&stackChild);
#ifdef Allocator_USE_CANARIES
- child->nextCanary = child->canary = parent->nextCanary;
+ stackChild.nextCanary = stackChild.canary = parent->nextCanary;
#endif
+
struct Allocator_pvt* child =
newAllocation(&stackChild, sizeof(struct Allocator_pvt), file, line);
Bits_memcpyConst(child, &stackChild, sizeof(struct Allocator_pvt));
@@ -721,8 +687,8 @@ struct Allocator* Allocator_new(unsigned long sizeLimit,
.lineNum = lineNum,
},
#ifdef Allocator_USE_CANARIES
- .canary = (long) 0x09F911029D74E35Bll,
- .nextCanary = (long) 0xD84156C5635688C0ll,
+ .canary = (unsigned long) CompileTimeRandom_uint64(),
+ .nextCanary = (unsigned long) CompileTimeRandom_uint64(),
#endif
}
};
View
4 memory/Allocator.h
@@ -20,10 +20,6 @@
#include "util/Linker.h"
Linker_require("memory/Allocator.c")
-#if !defined(Allocator_USE_CANARIES) && defined(PARANOIA)
- //#define Allocator_USE_CANARIES
-#endif
-
/**
* A handle which is provided in response to calls to Allocator_onFree().
* This handle is sutable for use with Allocator_notOnFree() to cancel a job.
View
8 memory/Allocator_pvt.h
@@ -31,8 +31,8 @@ struct Allocator_OnFreeJob_pvt {
/* prevent async jobs from being called multiple times, nonzero = done */
int done;
- const char* file;
int line;
+ const char* file;
/** Set by allocator. */
Identity
@@ -43,7 +43,7 @@ struct Allocator_Allocation_pvt {
struct Allocator_Allocation pub;
struct Allocator_Allocation_pvt* next;
#ifdef Allocator_USE_CANARIES
- long beginCanary;
+ unsigned long beginCanary;
#endif
};
@@ -103,10 +103,10 @@ struct Allocator_pvt
#ifdef Allocator_USE_CANARIES
/** The canary for allocations made with this allocator constant to allow varification. */
- long canary;
+ unsigned long canary;
/** The canary which will be used for the next allocator, mutable. */
- long nextCanary;
+ unsigned long nextCanary;
#endif
/** For checking structure integrity. */
View
12 net/Ducttape.c
@@ -426,11 +426,13 @@ static uint8_t magicInterfaceSendMessage(struct Message* msg, struct Interface*
Identity_cast((struct Ducttape_pvt*)
&((uint8_t*)iface)[-offsetof(struct Ducttape, magicInterface)]);
- Assert_true(msg->length >= Headers_IP6Header_SIZE);
- struct Headers_IP6Header* header = (struct Headers_IP6Header*) msg->bytes;
+ #ifdef PARANOIA
+ Assert_true(msg->length >= Headers_IP6Header_SIZE);
+ struct Headers_IP6Header* header = (struct Headers_IP6Header*) msg->bytes;
- Assert_true(!Bits_memcmp(header->destinationAddr, ctx->myAddr.ip6.bytes, 16));
- Assert_true(!Bits_memcmp(header->sourceAddr, FC_ONE, 16));
+ Assert_true(!Bits_memcmp(header->destinationAddr, ctx->myAddr.ip6.bytes, 16));
+ Assert_true(!Bits_memcmp(header->sourceAddr, FC_ONE, 16));
+ #endif
TUNMessageType_push(msg, Ethernet_TYPE_IP6, NULL);
@@ -882,7 +884,7 @@ static uint8_t outgoingFromCryptoAuth(struct Message* message, struct Interface*
Log_debug(context->logger, "Sending layer3 message");
return outgoingFromMe(message, dtHeader, session, context);
} else {
- Assert_true(0);
+ Assert_always(0);
}
}
View
2  net/test/DefaultInterfaceController_multiIface_test.c
@@ -47,7 +47,7 @@ int main()
Message_push(msg, "The Key ", 8, NULL);
iface.receiveMessage(msg, &iface);
- Assert_true(allocatorsFreed == 1);
+ Assert_always(allocatorsFreed == 1);
Allocator_free(alloc);
return 0;
View
4 node_build/Tests.js
@@ -18,7 +18,7 @@ var nThen = require("nthen");
var Tests = module.exports;
var getTests = function (file, tests, callback) {
- if (/\/(.git|buildjs|node_build|contrib|windows)\//.test(file)) { callback(); return; }
+ if (/\/(.git|buildjs|node_build|contrib)\//.test(file)) { callback(); return; }
Fs.stat(file, function (err, stat) {
if (err) { throw err; }
if (stat.isDirectory()) {
@@ -33,7 +33,7 @@ var getTests = function (file, tests, callback) {
callback();
});
return;
- } else if (/_test\.c$/.test(file)) {
+ } else if (/_test\.c$/.test(file) && tests.indexOf(file) === -1) {
tests.push(file);
}
callback();
View
122 node_build/builder.js
@@ -108,7 +108,7 @@ var execJs = function (js, state, file, fileName, callback) {
err = e;
err.message += "\nContent: [" + js + "]";
clearTimeout(to);
- process.nextTick(function() { callback(res); });
+ throw err;
}
}).nThen(function (waitFor) {
if (err) { return; }
@@ -120,26 +120,67 @@ var execJs = function (js, state, file, fileName, callback) {
var debug = console.log;
+var preprocessBlock = function (block, state, fileObj, fileName, callback) {
+ // a block is an array of strings and arrays, any inside arrays must be
+ // preprocessed first. deep first top to bottom.
+
+ var error = false;
+ var nt = nThen;
+ block.forEach(function (elem, i) {
+ if (typeof(elem) === 'string') { return; }
+ nt = nt(function (waitFor) {
+ preprocessBlock(elem, state, fileObj, fileName, waitFor(function (err, ret) {
+ if (err) { throw err; }
+ block[i] = ret;
+ }));
+ }).nThen;
+ });
+
+ nt(function (waitFor) {
+ if (error) { return; }
+ var capture = block.join('');
+ execJs(capture, state, fileObj, fileName, waitFor(function (err, ret) {
+ if (err) { throw err; }
+ callback(undefined, ret);
+ }));
+ });
+};
+
var preprocess = function (content, state, fileObj, fileName, callback) {
- var elems;
- nThen(function (waitFor) {
- elems = content.split('<?js');
- elems.forEach(function (elem, i) {
- if (!i) { return; }
- var capture = elem.substring(0,elem.indexOf('?>'));
- var remainder = elem.substring(capture.length+2);
- execJs(capture, state, fileObj, fileName, waitFor(function (err, ret) {
- if (err) {
- callback(err);
- callback = function() {};
- return;
- }
- //debug('[' + capture + '] --> [' + ret + '] [' + remainder.substring(0,100) + ']');
- elems[i] = ret + remainder;
- //if (elems[i].indexOf('?>') !== -1) { throw new Error(); }
+ // <?js file.Test_mainFunc = "<?js return 'RootTest_'+file.RootTest_mainFunc; ?>" ?>
+ // worse:
+ // <?js file.Test_mainFunc = "<?js var done = this.async(); process.nextTick(done); ?>" ?>
+
+ var flatArray = content.split(/(<\?js|\?>)/);
+ var elems = [];
+ var unflatten = function (array, startAt, out) {
+ for (var i = startAt; i < array.length; i++) {
+ if (!((i - startAt) % 2)) {
+ out.push(array[i]);
+ } else if (array[i] === '<?js') {
+ var next = [];
+ out.push(next);
+ i = unflatten(array, i+1, next);
+ } else if (array[i] === '?>') {
+ return i;
+ }
+ }
+ return i;
+ };
+ if (unflatten(flatArray, 0, elems) !== flatArray.length) { throw new Error() };
+
+ var nt = nThen;
+ elems.forEach(function (elem, i) {
+ if (typeof(elem) === 'string') { return; }
+ nt = nt(function (waitFor) {
+ preprocessBlock(elem, state, fileObj, fileName, waitFor(function (err, ret) {
+ if (err) { throw err; }
+ elems[i] = ret;
}));
- });
- }).nThen(function (waitFor) {
+ }).nThen;
+ });
+
+ nt(function (waitFor) {
callback(undefined, elems.join(''));
});
};
@@ -174,7 +215,7 @@ var compileFile = function (fileName, state, tempDir, callback)
currentlyCompiling[fileName].push(callback);
//debug('\033[2;32mCompiling ' + fileName + '\033[0m');
- var preprocessed = tempDir + '/' + getObjectFile(fileName) + '.i';
+ var preprocessed = state.buildDir+'/'+getObjectFile(fileName)+'.i';
var outFile = state.buildDir+'/'+getObjectFile(fileName);
var fileContent;
var fileObj = getFile();
@@ -209,6 +250,15 @@ var compileFile = function (fileName, state, tempDir, callback)
}).nThen(function (waitFor) {
+ Fs.exists(preprocessed, waitFor(function (exists) {
+ if (!exists) { return; }
+ Fs.unlink(preprocessed, waitFor(function (err) {
+ if (err) { throw err; }
+ }));
+ }));
+
+ }).nThen(function (waitFor) {
+
//debug("Preprocess");
preprocess(fileContent, state, fileObj, fileName, waitFor(function (err, output) {
if (err) { throw err; }
@@ -224,11 +274,10 @@ var compileFile = function (fileName, state, tempDir, callback)
}));
Fs.exists(outFile, waitFor(function (exists) {
- if (exists) {
- Fs.unlink(outFile, waitFor(function (err) {
- if (err) { throw err; }
- }));
- }
+ if (!exists) { return; }
+ Fs.unlink(outFile, waitFor(function (err) {
+ if (err) { throw err; }
+ }));
}));
}).nThen(function (waitFor) {
@@ -488,7 +537,9 @@ module.exports.configure = function (params, configure) {
}
var state;
- var buildStage;
+ var buildStage = function () {};
+ var testStage = function () {};
+ var packStage = function () {};
nThen(function(waitFor) {
// make the build directory
@@ -531,6 +582,7 @@ module.exports.configure = function (params, configure) {
state.buildDir = params.buildDir;
for (var i = 0; i < state.includeDirs.length; i++) {
+ if (state.cflags[state.cflags.indexOf(state.includeDirs[i])-1] == '-I') { continue; }
state.cflags.push('-I');
state.cflags.push(state.includeDirs[i]);
}
@@ -571,6 +623,14 @@ module.exports.configure = function (params, configure) {
debug("Compile " + time() + "ms");
+ }).nThen(function (waitFor) {
+
+ testStage({ }, waitFor);
+
+ }).nThen(function(waitFor) {
+
+ packStage({ }, waitFor);
+
}).nThen(function(waitFor) {
getMTimes(state.files, state.mtimes, waitFor(function (err, mtimes) {
@@ -592,6 +652,16 @@ module.exports.configure = function (params, configure) {
return {
build: function (build) {
buildStage = build;
+ return {
+ test: function (test) {
+ testStage = test;
+ return {
+ pack: function (pack) {
+ packStage = pack;
+ }
+ };
+ }
+ };
}
};
};
View
39 node_build/make.js
@@ -65,7 +65,8 @@ require('./builder').configure({
buildDir: 'buildjs'
}, function(builder, waitFor) {
- builder.config.systemName = 'Linux';
+ // ['linux','darwin','sunos','win32','freebsd']
+ builder.config.systemName = 'linux';
builder.config.tempDir = '/tmp';
builder.config.useTempFiles = true;
builder.config.cflags.push(
@@ -75,7 +76,7 @@ require('./builder').configure({
'-Werror',
'-Wno-pointer-sign',
'-pedantic',
- '-D','Linux=1',
+ '-D',builder.config.systemName + '=1',
'-D','HAS_ETH_INTERFACE=1',
'-Wno-unused-parameter',
'-Wno-unused-result',
@@ -93,6 +94,7 @@ require('./builder').configure({
'-D','Log_DEBUG',
'-D','CJDNS_MAX_PEERS=256',
'-D','Identity_CHECK=1',
+ '-D','Allocator_USE_CANARIES=1',
'-D','PARANOIA=1',
'-D','HAS_JS_PREPROCESSOR'
);
@@ -154,13 +156,38 @@ require('./builder').configure({
}).build(function (builder, waitFor) {
- builder.compile('admin/angel/cjdroute2.c', 'cjdroute');
- builder.compile('publictoip6.c', 'publictoip6');
- builder.compile('privatetopublic.c', 'privatetopublic');
- builder.compile('testcjdroute.c', 'testcjdroute');
+ builder.compile('admin/angel/cjdroute2.c', './buildjs/cjdroute');
+ builder.compile('publictoip6.c', './buildjs/publictoip6');
+ builder.compile('privatetopublic.c', './buildjs/privatetopublic');
+ builder.compile('testcjdroute.c', './buildjs/testcjdroute');
Codestyle.checkDir('.', true, waitFor(function (err) {
if (err) { console.log("Codestyle error"); throw err; }
}));
+}).test(function (builder, waitFor) {
+
+ var out = '';
+ var test = Spawn('./buildjs/testcjdroute');
+ test.stdout.on('data', function(dat) { out += dat.toString(); });
+ test.stderr.on('data', function(dat) { process.stderr.write(dat.toString()); });
+ test.on('close', waitFor(function (ret) {
+ if (ret !== 0) {
+ console.log(out);
+ console.log('\033[1;31mFailed to build cjdns.\033[0m');
+ waitFor.abort();
+ } else {
+ console.log('\033[1;32mBuild completed successfully, type ./cjdroute to begin setup.\033[0m');
+ }
+ }));
+
+}).pack(function (builder, waitFor) {
+
+ Fs.exists('./buildjs/cjdroute', waitFor(function (exists) {
+ if (!exists) { return; }
+ Fs.rename('./buildjs/cjdroute', './cjdroute', waitFor(function (err) {
+ if (err) { throw err; }
+ }));
+ }));
+
});
View
2  switch/test/LabelSplicer_test.c
@@ -21,7 +21,7 @@
static void unsplice()
{
- Assert_true(0x13 == LabelSplicer_unsplice(0x13, 1));
+ Assert_always(0x13 == LabelSplicer_unsplice(0x13, 1));
}
static void splice()
View
56 test/RootTest.h
@@ -0,0 +1,56 @@
+/* vim: set expandtab ts=4 sw=4: */
+/*
+ * You may redistribute this program and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef RootTest_H
+#define RootTest_H
+
+#include "benc/String.h"
+#include <stdio.h>
+
+#define RootTest_toStr(x) RootTest_toStr2(x)
+#define RootTest_toStr2(x) #x
+<?js file.RootTest_mainFunc = RootTest_toStr(main) ?>
+
+#define RootTest_main <?js return 'RootTest_'+file.RootTest_mainFunc; ?>
+
+int RootTest_main(int argc, char** argv);
+int main(int argc, char** argv)
+{
+ int runIt = 0;
+ int j = 0;
+ for (int i = 0; i < argc; i++) {
+ argv[j] = argv[i];
+ if (String_equals(String_CONST("+roottest"), String_CONST(argv[i]))) {
+ j--;
+ runIt = 1;
+ }
+ j++;
+ }
+ if (runIt) {
+ return RootTest_main(j,argv);
+ } else {
+ printf("Root test %s disabled, use [%s +roottest] to include it\n", RootTest_toStr(main),
+ (argc > 0) ? argv[0] : "");
+ }
+ return 0;
+}
+
+#ifdef main
+ #undef main
+#endif
+
+#define main RootTest_main // CHECKFILES_IGNORE
+int main(int argc, char** argv);
+
+#endif
View
2  test/cjdroute_routerPing_test.c
@@ -37,7 +37,7 @@ int main()
char* pingBenc = "d1:q4:ping4:txid4:abcd1:pi2ee";
struct Allocator* alloc = MallocAllocator_new(1<<22);
struct TestFramework* tf = TestFramework_setUp("0123456789abcdefghijklmnopqrstuv", alloc, NULL);
- struct Ducttape_pvt* dt = Identity_cast((struct Ducttape_pvt*) tf->ducttape);
+ struct Ducttape_pvt* dt = (struct Ducttape_pvt*) tf->ducttape;
struct Allocator* allocator = MallocAllocator_new(85000);
uint16_t buffLen = sizeof(struct Ducttape_IncomingForMe) + 8 + strlen(pingBenc);
View
6 test/threeNodes_test.c
@@ -35,7 +35,7 @@
#define TUNA 1
static uint8_t incomingTunC(struct Message* msg, struct Interface* iface)
{
- Assert_true(TUNMessageType_pop(msg, NULL) == Ethernet_TYPE_IP6);
+ Assert_always(TUNMessageType_pop(msg, NULL) == Ethernet_TYPE_IP6);
Message_shift(msg, -Headers_IP6Header_SIZE, NULL);
printf("Message from TUN in node C [%s] [%d]\n", msg->bytes, msg->length);
*((int*)iface->senderContext) = TUNC;
@@ -44,7 +44,7 @@ static uint8_t incomingTunC(struct Message* msg, struct Interface* iface)
static uint8_t incomingTunB(struct Message* msg, struct Interface* iface)
{
- Assert_true(TUNMessageType_pop(msg, NULL) == Ethernet_TYPE_IP6);
+ Assert_always(TUNMessageType_pop(msg, NULL) == Ethernet_TYPE_IP6);
Message_shift(msg, -Headers_IP6Header_SIZE, NULL);
printf("Message from TUN in node B [%s]\n", msg->bytes);
*((int*)iface->senderContext) = TUNB;
@@ -53,7 +53,7 @@ static uint8_t incomingTunB(struct Message* msg, struct Interface* iface)
static uint8_t incomingTunA(struct Message* msg, struct Interface* iface)
{
- Assert_true(TUNMessageType_pop(msg, NULL) == Ethernet_TYPE_IP6);
+ Assert_always(TUNMessageType_pop(msg, NULL) == Ethernet_TYPE_IP6);
Message_shift(msg, -Headers_IP6Header_SIZE, NULL);
uint8_t buff[1024];
Hex_encode(buff, 1024, msg->bytes, msg->length);
View
4 test/twoNodes_test.c
@@ -34,7 +34,7 @@
#define TUNA 1
static uint8_t incomingTunB(struct Message* msg, struct Interface* iface)
{
- Assert_true(TUNMessageType_pop(msg, NULL) == Ethernet_TYPE_IP6);
+ Assert_always(TUNMessageType_pop(msg, NULL) == Ethernet_TYPE_IP6);
Message_shift(msg, -Headers_IP6Header_SIZE, NULL);
printf("Message from TUN in node B [%s]\n", msg->bytes);
*((int*)iface->senderContext) = TUNB;
@@ -42,7 +42,7 @@ static uint8_t incomingTunB(struct Message* msg, struct Interface* iface)
}
static uint8_t incomingTunA(struct Message* msg, struct Interface* iface)
{
- Assert_true(TUNMessageType_pop(msg, NULL) == Ethernet_TYPE_IP6);
+ Assert_always(TUNMessageType_pop(msg, NULL) == Ethernet_TYPE_IP6);
Message_shift(msg, -Headers_IP6Header_SIZE, NULL);
printf("Message from TUN in node A [%s]\n", msg->bytes);
*((int*)iface->senderContext) = TUNA;
View
72 testcjdroute.c
@@ -12,6 +12,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#define string_strlen
+#define string_strcmp
+#include "util/Assert.h"
+#include "util/platform/libc/string.h"
+#include "util/events/Time.h"
+#include "util/events/EventBase.h"
+#include "memory/MallocAllocator.h"
+
#include <stdio.h>
<?js
@@ -19,23 +27,71 @@
var Tests = require("./Tests");
Tests.get(function (tests) {
var prototypes = [];
- var mainContent = [];
+ var listContent = [];
tests.forEach(function (test) {
var main = /^.*\/([^\/]+)\.c$/.exec(test)[1] + '_main';
(state['cflags'+test] = state['cflags'+test] || []).push('-D', 'main='+main);
file.links.push(test);
- mainContent.push('printf("'+test+'\\n");');
- mainContent.push(main+'(argc, argv);');
+ listContent.push('{ .func = '+main+', .name = "'+test.replace(/^.*\/|.c$/g, '')+'" },');
prototypes.push('int '+main+'(int argc, char** argv);');
});
- done(prototypes.join('\n'));
- process.nextTick(function() { mainDone(mainContent.join('\n')); });
+ file.testcjdroute_tests = listContent.join('\n');
+ file.testcjdroute_prototypes = prototypes.join('\n');
+ done();
});
?>
+<?js return file.testcjdroute_prototypes; ?>
+
+ typedef int (* Test)(int argc, char** argv);
+
+static struct {
+ Test func;
+ char* name;
+} TESTS[] = {
+ <?js return file.testcjdroute_tests ?>
+};
+
+static uint64_t runTest(Test test,
+ char* name,
+ uint64_t startTime,
+ int argc,
+ char** argv,
+ struct EventBase* base)
+{
+ fprintf(stderr, "Running test %s", name);
+ Assert_always(!test(argc, argv));
+ uint64_t now = Time_hrtime();
+ char* seventySpaces = " ";
+ int count = strlen(name);
+ if (count > 69) { count = 69; }
+ fprintf(stderr, "%s%d.%d ms\n",
+ &seventySpaces[count],
+ (int)((now - startTime)/1000000),
+ (int)((now - startTime)/1000)%1000);
+ return now;
+}
+
int main(int argc, char** argv)
{
- <?js
- mainDone = this.async();
- ?>
+ struct Allocator* alloc = MallocAllocator_new(4096);
+ struct EventBase* base = EventBase_new(alloc);
+ uint64_t now = Time_hrtime();
+ uint64_t startTime = now;
+ if (argc > 1) {
+ for (int i = 0; i < (int)(sizeof(TESTS)/sizeof(*TESTS)); i++) {
+ if (!strcmp(TESTS[i].name, argv[1])) {
+ TESTS[i].func(argc, argv);
+ return 0;
+ }
+ }
+ }
+ for (int i = 0; i < (int)(sizeof(TESTS)/sizeof(*TESTS)); i++) {
+ now = runTest(TESTS[i].func, TESTS[i].name, now, argc, argv, base);
+ }
+ fprintf(stderr, "Total test time %d.%d ms\n",
+ (int)((now - startTime)/1000000),
+ (int)((now - startTime)/1000)%1000);
+ Allocator_free(alloc);
+ return 0;
}
View
4 tunnel/IpTunnel_admin.c
@@ -153,7 +153,7 @@ static void showConn(struct IpTunnel_Connection* conn,
if (!Bits_isZero(conn->connectionIp6, 16)) {
struct Sockaddr* addr = Sockaddr_clone(Sockaddr_LOOPBACK6, alloc);
uint8_t* address;
- Assert_true(16 == Sockaddr_getAddress(addr, &address));
+ Assert_always(16 == Sockaddr_getAddress(addr, &address));
Bits_memcpyConst(address, conn->connectionIp6, 16);
char* printedAddr = Sockaddr_print(addr, alloc);
Dict_putString(d, String_CONST("ip6Address"), String_CONST(printedAddr), alloc);
@@ -162,7 +162,7 @@ static void showConn(struct IpTunnel_Connection* conn,
if (!Bits_isZero(conn->connectionIp4, 4)) {
struct Sockaddr* addr = Sockaddr_clone(Sockaddr_LOOPBACK, alloc);
uint8_t* address;
- Assert_true(4 == Sockaddr_getAddress(addr, &address));
+ Assert_always(4 == Sockaddr_getAddress(addr, &address));
Bits_memcpyConst(address, conn->connectionIp4, 4);
char* printedAddr = Sockaddr_print(addr, alloc);
Dict_putString(d, String_CONST("ip4Address"), String_CONST(printedAddr), alloc);
View
4 tunnel/test/IpTunnel_test.c
@@ -74,7 +74,7 @@ static uint8_t responseWithIpCallback(struct Message* message, struct Interface*
static uint8_t messageToTun(struct Message* message, struct Interface* iface)
{
- Assert_true(TUNMessageType_pop(message, NULL) == Ethernet_TYPE_IP6);
+ Assert_always(TUNMessageType_pop(message, NULL) == Ethernet_TYPE_IP6);
struct Headers_IP6Header* ip = (struct Headers_IP6Header*) message->bytes;
Assert_always(Headers_getIpVersion(ip) == 6);
uint16_t length = Endian_bigEndianToHost16(ip->payloadLength_be);
@@ -157,7 +157,7 @@ int main()
ipTun->tunInterface.receiveMessage = messageToTun;
ipTun->nodeInterface.sendMessage(message, &ipTun->nodeInterface);
- Assert_true(called);
+ Assert_always(called);
Allocator_free(alloc);
return 0;
View
2  util/Assert.h
@@ -45,6 +45,8 @@ void Assert_failure(const char* format, ...);
#ifdef PARANOIA
#define Assert_true(expr) Assert_always(expr)
+#else
+ #define Assert_true(expr)
#endif
#endif
View
3  util/Bits.h
@@ -17,7 +17,6 @@
#include "util/Assert.h"
#include "util/Endian.h"
-#include "util/log/Log.h"
#include "util/Gcc.h"
#include <stdint.h>
@@ -182,7 +181,7 @@ static inline void* Bits_memcpyDebug(void* out,
* @param in the buffer to read from.
* @param length the number of bytes to copy.
*/
-#ifdef Log_DEBUG
+#ifdef PARANOIA
#define Bits_memcpy(a, b, c) Bits_memcpyDebug(a, b, c, Gcc_SHORT_FILE, Gcc_LINE)
#else
#define Bits_memcpy(a,b,c) Bits_memcpyNoDebug(a,b,c)
View
32 util/CompileTimeRandom.h
@@ -0,0 +1,32 @@
+/* vim: set expandtab ts=4 sw=4: */
+/*
+ * You may redistribute this program and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef CompileTimeRandom_H
+#define CompileTimeRandom_H
+
+#define CompileTimeRandom_uint64() ((uint64_t) <?js return \
+ '0x' + (Math.random().toString(16) + Math.random().toString(16)).replace(/0\./g, '') + 'ull' \
+?>)
+
+#define CompileTimeRandom_uint32() ((uint32_t) <?js return \
+ '0x' + Math.random().toString(16).replace(/0\./g, '') + 'ul' \
+?>)
+
+#define CompileTimeRandom_hexString(len) <?js \
+ var hex = ''; \
+ while (hex.length < len) { hex += Math.random().toString(16).substring(2); } \
+ return '"' + hex.substring(0,len) + '"'; \
+?>
+
+#endif
View
6 util/Endian.h
@@ -17,15 +17,15 @@
#include <stdint.h>
-#ifdef Linux
+#ifdef linux
#include <byteswap.h>
#endif
-#ifdef Darwin
+#ifdef darwin
#include <libkern/OSByteOrder.h>
#endif
-#ifdef BSD
+#ifdef freebsd
#include <sys/endian.h>
#endif
View
21 util/Gcc.h
@@ -20,24 +20,25 @@
#define Gcc_PRINTF( format_idx, arg_idx ) \
__attribute__((__format__ (__printf__, format_idx, arg_idx)))
#define Gcc_NORETURN \
- __attribute__((__noreturn__))
+ __attribute__((__noreturn__))
+
+#define Gcc_NONNULL(num) \
+ __attribute__((__nonnull__(num)))
+
+#define Gcc_PURE \
+ __attribute__ ((__pure__))
+
#else
#define Gcc_PRINTF( format_idx, arg_idx )
#define Gcc_NORETURN
+#define Gcc_NONNULL(num)
+#define Gcc_PURE
#endif
-#ifdef HAS_JS_PREPROCESSOR
-#define Gcc_SHORT_FILE <?\
-js \
- return '"'+__FILE__.substring(__FILE__.lastIndexOf('/')+1)+'"'; \
-?>
-#else
- #define Gcc_SHORT_FILE __FILE__
-#endif
-
+#define Gcc_SHORT_FILE <?js return '"'+__FILE__.substring(__FILE__.lastIndexOf('/')+1)+'"'; ?>
#define Gcc_LINE __LINE__
Gcc_PRINTF(1,2)
View
11 util/Identity.h
@@ -16,16 +16,17 @@
#define Identity_H
#include "util/Assert.h"
+#include "util/CompileTimeRandom.h"
-#ifndef Identity_MAGIC
- #define Identity_MAGIC ((unsigned int) 0x01234567)
-#endif
+<?js file.Identity_hash = "0x" + CompileTimeRandom_hexString(16) + "ull"; ?>
+
+#define Identity_MAGIC ((unsigned long) <?js return file.Identity_hash ?>)
-#if defined(Identity_CHECK) || defined(PARANOIA)
+#if defined(Identity_CHECK)
/** This goes in each structure which will be checked. */
#define Identity \
- unsigned int Identity_verifier;
+ unsigned long Identity_verifier;
#define Identity_set(pointer) \
(pointer)->Identity_verifier = Identity_MAGIC
View
2  util/events/libuv/Event.c
@@ -62,7 +62,7 @@ struct Event* Event_socketRead(void (* const callback)(void* callbackContext),
struct Allocator* allocator,
struct Except* eh)
{
- struct EventBase_pvt* base = Identity_cast((struct EventBase_pvt*) eventBase);
+ struct EventBase_pvt* base = EventBase_privatize(eventBase);
struct Allocator* alloc = Allocator_child(allocator);
struct Event_pvt* out = Allocator_clone(alloc, (&(struct Event_pvt) {
.callback = callback,
View
5 util/events/libuv/EventBase.c
@@ -114,3 +114,8 @@ int EventBase_eventCount(struct EventBase* eventBase)
uv_walk(ctx->loop, countCallback, &eventCount);
return eventCount;
}
+
+struct EventBase_pvt* EventBase_privatize(struct EventBase* base)
+{
+ return Identity_cast((struct EventBase_pvt*) base);
+}
View
2  util/events/libuv/EventBase_pvt.h
@@ -44,4 +44,6 @@ struct EventBase_pvt
Identity
};
+struct EventBase_pvt* EventBase_privatize(struct EventBase* base);
+
#endif
View
6 util/events/libuv/Pipe.c
@@ -332,7 +332,7 @@ static struct Pipe_pvt* newPipe(struct EventBase* eb,
struct Except* eh,
struct Allocator* userAlloc)
{
- struct EventBase_pvt* ctx = Identity_cast((struct EventBase_pvt*) eb);
+ struct EventBase_pvt* ctx = EventBase_privatize(eb);
struct Allocator* alloc = Allocator_child(userAlloc);
#ifdef Windows
@@ -389,7 +389,7 @@ struct Pipe* Pipe_forFiles(int inFd,
snprintf(buff, 31, "forFiles(%d,%d)", inFd, outFd);
struct Pipe_pvt* out = newPipe(eb, buff, eh, userAlloc);
- struct EventBase_pvt* ctx = Identity_cast((struct EventBase_pvt*) eb);
+ struct EventBase_pvt* ctx = EventBase_privatize(eb);
if (uv_pipe_open(&out->peer, inFd)) {
Except_throw(eh, "uv_pipe_open(inFd) failed [%s]",
@@ -416,7 +416,7 @@ struct Pipe* Pipe_named(const char* name,
struct Allocator* userAlloc)
{
struct Pipe_pvt* out = newPipe(eb, name, eh, userAlloc);
- struct EventBase_pvt* ctx = Identity_cast((struct EventBase_pvt*) eb);
+ struct EventBase_pvt* ctx = EventBase_privatize(eb);
// Attempt to create pipe.
if (!uv_pipe_bind(&out->server, out->pub.fullName)) {
View
2  util/events/libuv/Process.c
@@ -44,7 +44,7 @@ static int onFree(struct Allocator_OnFreeJob* job)
int Process_spawn(char* binaryPath, char** args, struct EventBase* base, struct Allocator* alloc)
{
- struct EventBase_pvt* ctx = Identity_cast((struct EventBase_pvt*) base);
+ struct EventBase_pvt* ctx = EventBase_privatize(base);
int i;
for (i = 0; args[i]; i++) ;
View
2  util/events/libuv/Time.c
@@ -26,7 +26,7 @@ uint64_t Time_hrtime()
uint64_t Time_currentTimeMilliseconds(struct EventBase* eventBase)
{
- struct EventBase_pvt* base = Identity_cast((struct EventBase_pvt*) eventBase);
+ struct EventBase_pvt* base = EventBase_privatize(eventBase);
return uv_now(base->loop) + base->baseTime;
}
View
2 &#