diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-05-07 18:11:18 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-05-07 18:11:18 +0000 |
commit | d6dd23d50411a11226a8dcd88e51aa0a332e499d (patch) | |
tree | b40988bcf0a7a5d3f7f745d78c2a687850d2cf5d /src/peerstore/gnunet-service-peerstore.c | |
parent | 603d264417198385513b09844ddf4557dcc44952 (diff) | |
download | gnunet-d6dd23d50411a11226a8dcd88e51aa0a332e499d.tar.gz gnunet-d6dd23d50411a11226a8dcd88e51aa0a332e499d.zip |
PEERSTORE api update
Diffstat (limited to 'src/peerstore/gnunet-service-peerstore.c')
-rw-r--r-- | src/peerstore/gnunet-service-peerstore.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index 777e40376..f56860971 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c | |||
@@ -75,6 +75,45 @@ handle_client_disconnect (void *cls, | |||
75 | } | 75 | } |
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Handle a store request from client | ||
79 | * | ||
80 | * @param cls unused | ||
81 | * @param client identification of the client | ||
82 | * @param message the actual message | ||
83 | */ | ||
84 | void handle_store (void *cls, | ||
85 | struct GNUNET_SERVER_Client *client, | ||
86 | const struct GNUNET_MessageHeader *message) | ||
87 | { | ||
88 | struct StoreRequestMessage *sreqm; | ||
89 | struct GNUNET_SERVER_TransmitContext *tc; | ||
90 | struct StoreResponseMessage *sresm; | ||
91 | uint16_t msg_size; | ||
92 | char *sub_system; | ||
93 | |||
94 | msg_size = ntohs(message->size); | ||
95 | GNUNET_break_op(msg_size > sizeof(struct GNUNET_MessageHeader) + sizeof(struct StoreRequestMessage)); | ||
96 | sreqm = (struct StoreRequestMessage *)&message[1]; | ||
97 | sub_system = (char *)&sreqm[1]; | ||
98 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received a store request (size: %lu) for sub system `%s' and peer `%s'\n", | ||
99 | msg_size, | ||
100 | sub_system, | ||
101 | GNUNET_i2s (&sreqm->peer)); | ||
102 | //TODO: do the actual storage | ||
103 | //create a fake response for testing | ||
104 | char *response = "This is a response"; | ||
105 | tc = GNUNET_SERVER_transmit_context_create (client); | ||
106 | sresm = malloc(sizeof(struct StoreResponseMessage) + strlen(response)); | ||
107 | sresm->header.type = htons(GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT); | ||
108 | sresm->header.size = htons(sizeof(struct StoreResponseMessage) + strlen(response)); | ||
109 | sresm->success = htons(GNUNET_NO); | ||
110 | sresm->emsg_size = htons(strlen(response)); | ||
111 | memcpy(&sresm[1], response, strlen(response)); | ||
112 | GNUNET_SERVER_transmit_context_append_message(tc, (struct GNUNET_MessageHeader *)sresm); | ||
113 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | ||
114 | } | ||
115 | |||
116 | /** | ||
78 | * Peerstore service runner. | 117 | * Peerstore service runner. |
79 | * | 118 | * |
80 | * @param cls closure | 119 | * @param cls closure |
@@ -87,7 +126,8 @@ run (void *cls, | |||
87 | const struct GNUNET_CONFIGURATION_Handle *c) | 126 | const struct GNUNET_CONFIGURATION_Handle *c) |
88 | { | 127 | { |
89 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 128 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
90 | {NULL, NULL, 0, 0} | 129 | {&handle_store, NULL, GNUNET_MESSAGE_TYPE_PEERSTORE_STORE, 0}, |
130 | {NULL, NULL, 0, 0} | ||
91 | }; | 131 | }; |
92 | char *database; | 132 | char *database; |
93 | 133 | ||