Statistics
| Branch: | Revision:

napa-baselibs / tests / peer / peer.c @ 507372bb

History | View | Annotate | Download (1.93 KB)

1 956892f0 ArpadBakay
/*
2 507372bb CsabaKiraly
 * NAPA test peer implementation
3 956892f0 ArpadBakay
 */
4
5
#include        "peer.h"
6
7
Peer *peer = NULL;
8
9
#if 0
10
/** Helper to print a string list */
11
const char *print_list(char **list, int n, bool should_free) {
12
        static char buffer[4096];
13
        strcpy(buffer, "[ ");
14
        int i;
15
        for (i = 0; i != n; i++) {
16
                if (i) strcat(buffer, ", ");
17
                strcat(buffer, list[i]);
18
                if (should_free) free(list[i]);
19
        }
20
        strcat(buffer, " ]");
21
        if (should_free) free(list);
22
        return buffer;
23
}
24

25
void getPeers_callback(HANDLE client, HANDLE id, void *cbarg, char **result, int n) {
26
        info("GetPeers id %p done, result: %s", id, print_list(result, n, 1));
27
}
28

29
void showPeers() {
30
        int ncons = 0;
31
        int nranks = 0;
32
        Constraint *cons = NULL;
33
        Ranking *ranks = NULL;
34
        if (ncons) cons = calloc(ncons, sizeof(Constraint));
35
        if (nranks) ranks = calloc(nranks, sizeof(Ranking));
36
        HANDLE h = repGetPeers(peer->repository, getPeers_callback, NULL,0, cons, ncons, ranks, nranks);
37
}
38
#endif
39
40
41
int main(int argc, char *argv[]) {
42
        if (argc != 2) {
43
                fprintf(stderr, "Usage: peer config.cfg\n");
44
                exit(-1);
45
        }
46
47 507372bb CsabaKiraly
        napaInitLog(LOG_INFO, NULL, NULL);                /* Initialize logging */
48
        peer = peer_init(argv[1]);        /* Initialize the NAPA infrastructure */
49 956892f0 ArpadBakay
50
        info("Initialization done");
51
52
        event_base_dispatch(eventbase);
53
54
        return 0;
55
}
56
57
#if 0
58
void newPeers_cb(HANDLE rep, void *cbarg) {
59
        peer->num_neighbors = peer->neighborlist_size;
60
        if (!peer->neighborlist) return;
61
        neighborlist_query(peer->neighborlist, peer->neighbors, &(peer->num_neighbors));
62

63
        int i;
64
        for (i = 0; i != peer->num_neighbors; i++) {
65
                socketID_handle remote_socketID = malloc(SOCKETID_SIZE);
66
                mlStringToSocketID(peer->neighbors[i].peer, remote_socketID);
67
                info("Opening connection to %s", peer->neighbors[i].peer);
68
                if(open_connection(remote_socketID,&receive_outconn_cb,"DUMMY ARG") != 0) {
69
                        error("ML open_connection failed to %s", peer->neighbors[i].peer);
70
                }
71
        }
72
}
73
#endif