Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added some tools

  • Loading branch information...
commit 43fae424fe34bbd63b637e063d9448f24fc98d70 1 parent fe3e48a
Caleb James DeLisle authored
View
10 CMakeLists.txt
@@ -230,6 +230,16 @@ target_link_libraries(cleanconfig
cjdmemory
cjdio
)
+add_executable(benc2json
+ benc2json.c
+)
+target_link_libraries(benc2json
+ cjdbenc_StandardBencSerializer
+ cjdbenc_JsonBencSerializer
+ cjdbenc
+ cjdmemory
+ cjdio
+)
#INSTALL(TARGETS cjdroute RUNTIME DESTINATION bin)
View
61 benc2json.c
@@ -0,0 +1,61 @@
+/* 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 string_strcmp
+#include "benc/Dict.h"
+#include "benc/serialization/BencSerializer.h"
+#include "benc/serialization/json/JsonBencSerializer.h"
+#include "benc/serialization/standard/StandardBencSerializer.h"
+#include "memory/MallocAllocator.h"
+#include "io/Reader.h"
+#include "io/FileReader.h"
+#include "io/Writer.h"
+#include "io/FileWriter.h"
+#include "util/platform/libc/string.h"
+
+#include <unistd.h>
+
+int main(int argc, char** argv)
+{
+ if (isatty(STDIN_FILENO)) {
+ printf("Usage: %s < input.benc > output.json\n", argv[0]);
+ printf("Or: %s -r < input.json > output.benc\n", argv[0]);
+ exit(0);
+ }
+
+ struct Allocator* allocator = MallocAllocator_new(1<<20);
+
+ const struct BencSerializer* parser = StandardBencSerializer_get();
+ const struct BencSerializer* serializer = JsonBencSerializer_get();
+
+ if (argc > 1 && !strcmp(argv[0], "-r")) {
+ const struct BencSerializer* p = parser;
+ parser = serializer;
+ serializer = p;
+ }
+
+ struct Reader* stdinReader = FileReader_new(stdin, allocator);
+ Dict config;
+ if (parser->parseDictionary(stdinReader, allocator, &config)) {
+ fprintf(stderr, "Failed to parse configuration.\n");
+ return -1;
+ }
+
+ struct Writer* stdoutWriter = FileWriter_new(stdout, allocator);
+ serializer->serializeDictionary(stdoutWriter, &config);
+
+ printf("\n");
+
+ Allocator_free(allocator);
+}
View
39 contrib/python/findnodes
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+# 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/>.
+
+import sys;
+import os;
+from cjdns import cjdns_connectWithAdminInfo;
+import json;
+from pprint import pprint;
+from time import sleep;
+
+cjdns = cjdns_connectWithAdminInfo();
+
+nodes = {};
+while (1):
+ i = 0;
+ newNodes = [];
+ while True:
+ table = cjdns.NodeStore_dumpTable(i);
+ routes = table['routingTable'];
+ for entry in routes:
+ if (not entry['ip'] in nodes):
+ nodes[entry['ip']] = 1;
+ newNodes.append(entry);
+ if (not 'more' in table):
+ break;
+ i += 1;
+ for entry in newNodes:
+ print json.dumps(entry);
+ sleep(30);
View
8 net/Ducttape.c
@@ -480,6 +480,14 @@ static inline uint8_t incomingFromTun(struct Message* message,
Message_shift(message, -(Headers_IP6Header_SIZE + Headers_CryptoAuth_SIZE));
// The message is now aligned on the content.
+ #ifdef Log_DEBUG
+ uint8_t destAddr[40];
+ AddrTools_printIp(destAddr, header->destinationAddr);
+ uint8_t nhAddr[60];
+ Address_print(nhAddr, &bestNext->address);
+ Log_debug(context->logger, "Sending to [%s] via [%s]", destAddr, nhAddr);
+ #endif
+
// This comes out at outgoingFromCryptoAuth() then outgoingFromMe()
context->session = session;
context->layer = Ducttape_SessionLayer_INNER;
Please sign in to comment.
Something went wrong with that request. Please try again.