-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Caleb James DeLisle
committed
Nov 25, 2012
1 parent
fe3e48a
commit 43fae42
Showing
4 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters