Exemple #1
0
void cjdnsadmin_fetch_peers(cjdnsadmin_t *adm)
{
    struct bencode *b = ben_dict();
    struct bencode *args = ben_dict();
    // TODO: fix memory leak
    ben_dict_set(b, ben_str("q"), ben_str("NodeStore_dumpTable"));
    ben_dict_set(b, ben_str("args"), args);
    ben_dict_set(args, ben_str("page"), ben_int(adm->fetch_peers_page));

    uv_buf_t buf;
    static char msg[256];
    buf.base = msg;
    buf.len = ben_encode2(msg, sizeof msg, b);

    AMNEW(uv_udp_send_t,writer);
    writer->data = b;
    uv_udp_send(writer,
            &adm->handle,
            &buf,1,
            adm->theaddr,
            on_written);

}
Exemple #2
0
BEN *ben_dec_d(RAW * raw)
{
	BEN *dict = ben_init(BEN_DICT);
	BEN *val = NULL;
	BEN *key = NULL;

	raw->p++;
	while (*raw->p != 'e') {
		key = ben_dec_s(raw);
		val = ben_dec_r(raw);
		ben_dict(dict, key, val);
	}
	++raw->p;

	return dict;
}