Permalink
Browse files

mostly done, need a few tests now

  • Loading branch information...
1 parent 79b6924 commit e8fb37a66a5b7c621c343781da16c2b0236bbafe Caleb James DeLisle committed Jun 4, 2012
Showing with 246 additions and 456 deletions.
  1. +31 −19 admin/Configurator.c
  2. +7 −28 cjdroute.c
  3. +67 −0 exception/Jmp.h
  4. +1 −0 interface/CMakeLists.txt
  5. +16 −163 interface/UDPInterface.c
  6. +14 −4 interface/UDPInterface.h
  7. +79 −242 interface/UDPInterface_admin.c
  8. +31 −0 interface/UDPInterface_admin.h
View
@@ -98,26 +98,38 @@ static void authorizedPasswords(List* list, struct Context* ctx)
static void udpInterface(Dict* config, struct Context* ctx)
{
Dict* udp = Dict_getDict(config, String_CONST("UDPInterface"));
- Dict* connectTo = Dict_getDict(udp, String_CONST("connectTo"));
- if (connectTo) {
- struct Dict_Entry* entry = *connectTo;
- while (entry != NULL) {
- String* key = (String*) entry->key;
- if (entry->val->type != Object_DICT) {
- Log_critical(ctx->logger, "interfaces.UDPInterface.connectTo: entry [%s] "
- "is not a dictionary type.", key->bytes);
- exit(-1);
- }
- Dict* value = entry->val->as.dictionary;
-
- Log_keys(ctx->logger, "Attempting to connect to node [%s].", key->bytes);
-
- struct Allocator* perCallAlloc = ctx->alloc->child(ctx->alloc);
- Dict_putString(value, String_CONST("address"), key, perCallAlloc);
- rpcCall(String_CONST("UDPInterface_beginConnection"), value, ctx, perCallAlloc);
- perCallAlloc->free(perCallAlloc);
- entry = entry->next;
+ if (udp) {
+ // Setup the interface.
+ String* bindStr = Dict_getString(udp, String_CONST("bind"));
+ Dict* d = Dict_new(ctx->alloc);
+ if (bindStr) {
+ Dict_putString(d, String_CONST("bindAddress"), bindStr, ctx->alloc);
+ }
+ rpcCall(String_CONST("UDPInterface_new"), d, ctx, ctx->alloc);
+
+ // Make the connections.
+ Dict* connectTo = Dict_getDict(udp, String_CONST("connectTo"));
+ if (connectTo) {
+ struct Dict_Entry* entry = *connectTo;
+ while (entry != NULL) {
+ String* key = (String*) entry->key;
+ if (entry->val->type != Object_DICT) {
+ Log_critical(ctx->logger, "interfaces.UDPInterface.connectTo: entry [%s] "
+ "is not a dictionary type.", key->bytes);
+ exit(-1);
+ }
+ Dict* value = entry->val->as.dictionary;
+
+ Log_keys(ctx->logger, "Attempting to connect to node [%s].", key->bytes);
+
+ struct Allocator* perCallAlloc = ctx->alloc->child(ctx->alloc);
+ Dict_putString(value, String_CONST("address"), key, perCallAlloc);
+ rpcCall(String_CONST("UDPInterface_beginConnection"), value, ctx, perCallAlloc);
+ perCallAlloc->free(perCallAlloc);
+
+ entry = entry->next;
+ }
}
}
}
View
@@ -20,7 +20,6 @@
#include "crypto/Crypto.h"
#include "crypto/CryptoAuth.h"
#include "crypto/CryptoAuth_benchmark.h"
-#include "dht/CJDHTConstants.h"
#include "dht/ReplyModule.h"
#include "dht/SerializationModule.h"
#include "dht/dhtcore/RouterModule_admin.h"
@@ -29,7 +28,7 @@
#include "interface/Interface.h"
#include "interface/TUNInterface.h"
#include "interface/TUNConfigurator.h"
-#include "interface/UDPInterface.h"
+#include "interface/UDPInterface_admin.h"
#include "io/Reader.h"
#include "io/FileReader.h"
#include "io/Writer.h"
@@ -38,7 +37,6 @@
#include "benc/serialization/json/JsonBencSerializer.h"
#include "util/Log.h"
#include "memory/MallocAllocator.h"
-#include "memory/BufferAllocator.h"
#include "memory/Allocator.h"
#include "net/Ducttape.h"
#include "net/DefaultInterfaceController.h"
@@ -83,12 +81,6 @@ struct Context
struct Admin* admin;
};
-struct UDPInterfaceContext
-{
- struct Context* context;
- struct UDPInterface* udpContext;
-};
-
struct User
{
uint64_t trust;
@@ -379,7 +371,7 @@ static void security(List* config, struct Log* logger, struct ExceptionHandler*
static void adminPing(Dict* input, void* vadmin, String* txid)
{
- Dict d = Dict_CONST(CJDHTConstants_QUERY, String_OBJ(String_CONST("pong")), NULL);
+ Dict d = Dict_CONST(String_CONST("q"), String_OBJ(String_CONST("pong")), NULL);
Admin_sendMessage(&d, txid, (struct Admin*) vadmin);
}
@@ -568,24 +560,11 @@ int main(int argc, char** argv)
sp,
context.allocator);
- Dict* interfaces = Dict_getDict(&config, String_CONST("interfaces"));
-
- Dict* udpConf = Dict_getDict(interfaces, String_CONST("UDPInterface"));
- if (udpConf) {
- String* bindStr = Dict_getString(udpConf, String_CONST("bind"));
- UDPInterface_new(context.base,
- (bindStr) ? bindStr->bytes : NULL,
- context.allocator,
- context.eHandler,
- context.logger,
- ifController,
- context.admin);
- }
-
- if (udpConf == NULL) {
- fprintf(stderr, "No interfaces configured to connect to.\n");
- return -1;
- }
+ UDPInterface_admin_register(context.base,
+ context.allocator,
+ context.logger,
+ context.admin,
+ ifController);
// pid file
String* pidFile = Dict_getString(&config, String_CONST("pidFile"));
View
@@ -0,0 +1,67 @@
+/* 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 Jmp_H
+#define Jmp_H
+
+#include "exception/ExceptionHandler.h"
+#include <setjmp.h>
+
+/**
+ * setjmp based exception handler.
+ *
+ * struct Jmp jmp;
+ * Jmp_try(jmp) {
+ * Do_somethingDangerous(&jmp.handler);
+ * } Jmp_catch {
+ * printf("failed %d %s", jmp.code, jmp.message);
+ * }
+ *
+ * Provides an easy way to implement the most basic try/catch functionality.
+ * the jmp structure must not be used for anything outside of the try block,
+ * calling jmp.handler.exception outside of a try block is undefined behavior.
+ */
+
+struct Jmp {
+ /** The exception handler which will trigger the entry into the catch block. */
+ struct ExceptionHandler handler;
+
+ /** The exception message if in the catch block, otherwise undefined. */
+ char* message;
+
+ /** The code if inside of the catch block, otherwise undefined. */
+ int code;
+
+ /** Internal setjmp buffer. */
+ jmp_buf buf;
+};
+
+/** Internal callback, this should not be called directly. */
+Gcc_NORETURN
+static void Jmp_callback(char* message, int code, struct ExceptionHandler* handler)
+{
+ struct Jmp* jmp = (struct Jmp*) handler;
+ jmp->message = message;
+ jmp->code = code;
+ longjmp(jmp->buf, 1);
+}
+
+#define Jmp_try(jmp) \
+ jmp.handler.exception = Jmp_callback; \
+ if (!setjmp(jmp.buf))
+// CHECKFILES_IGNORE squigly bracket will be added by the caller.
+
+#define Jmp_catch else
+
+#endif
View
@@ -21,6 +21,7 @@ endif()
add_library(interface
UDPInterface.c
+ UDPInterface_admin.c
${tunif}
${tunconf}
InterfaceConnector.c
Oops, something went wrong.

0 comments on commit e8fb37a

Please sign in to comment.