summaryrefslogtreecommitdiff
path: root/code/test/server.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2017-05-23 03:49:54 +0200
committerUros Majstorovic <majstor@majstor.org>2017-05-23 03:49:54 +0200
commit7c70a430f9c708be2fcce8c9a0d8cecde7f75fc0 (patch)
tree5ea4cfa8a21be07690c28161153017b7270bc54b /code/test/server.c
parent25de5e761daab8b897a4f09ff8503e6f43c299f9 (diff)
changes for proxy
Diffstat (limited to 'code/test/server.c')
-rw-r--r--code/test/server.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/code/test/server.c b/code/test/server.c
index a03267e..5bb36ef 100644
--- a/code/test/server.c
+++ b/code/test/server.c
@@ -17,11 +17,13 @@ ECPConnHandler handler_c;
ECPNode node;
ECPConnection conn;
-#define PTYPE_MSG 16
+#define CTYPE_TEST 0
+#define MTYPE_MSG 8
-ssize_t handle_open_c(ECPConnection *c, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_open_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
uint32_t seq = 0;
+ ecp_conn_handle_open(conn, t, p, s);
if (s < 0) {
printf("OPEN ERR:%ld\n", s);
return 0;
@@ -31,52 +33,47 @@ ssize_t handle_open_c(ECPConnection *c, unsigned char t, unsigned char *p, ssize
unsigned char *buf = ecp_pld_get_buf(payload);
char *msg = "PERA JE CAR!";
+ ecp_pld_set_type(payload, MTYPE_MSG);
strcpy((char *)buf, msg);
- ssize_t _rv = ecp_send(c, PTYPE_MSG, payload, 1000);
+ ssize_t _rv = ecp_send(conn, payload, sizeof(payload));
return 0;
}
-ssize_t handle_msg_c(ECPConnection *c, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_msg_c(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
printf("MSG C:%s size:%ld\n", p, s);
-
return s;
}
-ssize_t handle_msg_s(ECPConnection *c, unsigned char t, unsigned char *p, ssize_t s) {
+ssize_t handle_msg_s(ECPConnection *conn, unsigned char t, unsigned char *p, ssize_t s) {
printf("MSG S:%s size:%ld\n", p, s);
unsigned char payload[ECP_SIZE_PLD(1000)];
unsigned char *buf = ecp_pld_get_buf(payload);
char *msg = "VAISTINU JE CAR!";
+ ecp_pld_set_type(payload, MTYPE_MSG);
strcpy((char *)buf, msg);
- ssize_t _rv = ecp_send(c, PTYPE_MSG, payload, 1000);
+ ssize_t _rv = ecp_send(conn, payload, sizeof(payload));
return s;
}
-int conn_create(ECPConnection *c, unsigned char *p, size_t s) {
- c->handler = &handler_s;
- return ECP_OK;
-}
-
int main(int argc, char *argv[]) {
int rv;
rv = ecp_init(&ctx_s);
printf("ecp_init RV:%d\n", rv);
+ rv = ecp_conn_handler_init(&handler_s);
+ handler_s.msg[MTYPE_MSG] = handle_msg_s;
+ ctx_s.handler[CTYPE_TEST] = &handler_s;
+
rv = ecp_dhkey_generate(&ctx_s, &key_perma_s);
printf("ecp_dhkey_generate RV:%d\n", rv);
rv = ecp_sock_create(&sock_s, &ctx_s, &key_perma_s);
printf("ecp_sock_create RV:%d\n", rv);
- rv = ecp_conn_hander_init(&handler_s);
-
- handler_s.f[PTYPE_MSG] = handle_msg_s;
- sock_s.conn_create = conn_create;
-
rv = ecp_sock_open(&sock_s, "0.0.0.0:3000");
printf("ecp_sock_open RV:%d\n", rv);
@@ -85,6 +82,11 @@ int main(int argc, char *argv[]) {
rv = ecp_init(&ctx_c);
printf("ecp_init RV:%d\n", rv);
+
+ rv = ecp_conn_handler_init(&handler_c);
+ handler_c.msg[ECP_MTYPE_OPEN] = handle_open_c;
+ handler_c.msg[MTYPE_MSG] = handle_msg_c;
+ ctx_c.handler[CTYPE_TEST] = &handler_c;
rv = ecp_dhkey_generate(&ctx_c, &key_perma_c);
printf("ecp_dhkey_generate RV:%d\n", rv);
@@ -101,16 +103,10 @@ int main(int argc, char *argv[]) {
rv = ecp_node_init(&ctx_c, &node, "127.0.0.1:3000", &key_perma_s.public);
printf("ecp_node_init RV:%d\n", rv);
- rv = ecp_conn_create(&conn, &sock_c);
+ rv = ecp_conn_create(&conn, &sock_c, CTYPE_TEST);
printf("ecp_conn_create RV:%d\n", rv);
- rv = ecp_conn_hander_init(&handler_c);
- printf("ecp_conn_hander_init RV:%d\n", rv);
-
- handler_c.f[ECP_PTYPE_OPEN] = handle_open_c;
- handler_c.f[PTYPE_MSG] = handle_msg_c;
-
- rv = ecp_conn_open(&conn, &node, &handler_c);
+ rv = ecp_conn_open(&conn, &node);
printf("ecp_conn_open RV:%d\n", rv);
while (1) sleep(1);