Skip to content

Commit

Permalink
Added some tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb James DeLisle committed Nov 25, 2012
1 parent fe3e48a commit 43fae42
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Expand Up @@ -230,6 +230,16 @@ target_link_libraries(cleanconfig
cjdmemory cjdmemory
cjdio cjdio
) )
add_executable(benc2json
benc2json.c
)
target_link_libraries(benc2json
cjdbenc_StandardBencSerializer
cjdbenc_JsonBencSerializer
cjdbenc
cjdmemory
cjdio
)


#INSTALL(TARGETS cjdroute RUNTIME DESTINATION bin) #INSTALL(TARGETS cjdroute RUNTIME DESTINATION bin)


Expand Down
61 changes: 61 additions & 0 deletions 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);
}
39 changes: 39 additions & 0 deletions 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);
8 changes: 8 additions & 0 deletions net/Ducttape.c
Expand Up @@ -480,6 +480,14 @@ static inline uint8_t incomingFromTun(struct Message* message,
Message_shift(message, -(Headers_IP6Header_SIZE + Headers_CryptoAuth_SIZE)); Message_shift(message, -(Headers_IP6Header_SIZE + Headers_CryptoAuth_SIZE));
// The message is now aligned on the content. // 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() // This comes out at outgoingFromCryptoAuth() then outgoingFromMe()
context->session = session; context->session = session;
context->layer = Ducttape_SessionLayer_INNER; context->layer = Ducttape_SessionLayer_INNER;
Expand Down

0 comments on commit 43fae42

Please sign in to comment.