diff options
author | Uros Majstorovic <majstor@majstor.org> | 2017-08-03 21:16:00 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2017-08-03 21:16:00 +0200 |
commit | f33714d52452dd19781785ca3cdf3cbd2cce6212 (patch) | |
tree | 55c43e9116bcefb4915d8cd1b3ee38560294b018 /code/core | |
parent | 72520c7339f04849633114d9dca644e32f85e9fb (diff) |
proxy inteface removed; ctx has pack and pack_raw methods
Diffstat (limited to 'code/core')
-rw-r--r-- | code/core/core.c | 35 | ||||
-rw-r--r-- | code/core/core.h | 12 |
2 files changed, 16 insertions, 31 deletions
diff --git a/code/core/core.c b/code/core/core.c index 544f896..7a24d96 100644 --- a/code/core/core.c +++ b/code/core/core.c @@ -33,6 +33,9 @@ int ecp_ctx_create(ECPContext *ctx) { memset(ctx, 0, sizeof(ECPContext)); + ctx->pack = ecp_conn_pack; + ctx->pack_raw = ecp_pack_raw; + rv = ecp_crypto_init(&ctx->cr); if (rv) return rv; #ifdef ECP_WITH_HTABLE @@ -869,6 +872,12 @@ ssize_t ecp_pack(ECPContext *ctx, unsigned char *packet, size_t pkt_size, unsign return rv+ECP_SIZE_PKT_HDR; } + +ssize_t ecp_pack_raw(ECPSocket *sock, ECPConnection *proxy, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size) { + ECPContext *ctx = sock->ctx; + + return ecp_pack(ctx, packet, pkt_size, s_idx, c_idx, public, shsec, nonce, seq, payload, payload_size); +} ssize_t ecp_conn_pack(ECPConnection *conn, ECPNetAddr *addr, ecp_seq_t *seq, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size) { ecp_aead_key_t shsec; @@ -934,26 +943,6 @@ ssize_t ecp_conn_pack(ECPConnection *conn, ECPNetAddr *addr, ecp_seq_t *seq, uns return _rv; } -ssize_t ecp_proxy_pack(ECPConnection *conn, ECPNetAddr *addr, ecp_seq_t *seq, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size) { - ECPContext *ctx = conn->sock->ctx; - - if (conn->proxy && ctx->pr.init) { - return ctx->pr.pack(conn, addr, seq, packet, pkt_size, s_idx, c_idx, payload, payload_size); - } else { - return ecp_conn_pack(conn, addr, seq, packet, pkt_size, s_idx, c_idx, payload, payload_size); - } -} - -ssize_t ecp_proxy_pack_raw(ECPSocket *sock, ECPConnection *proxy, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size) { - ECPContext *ctx = sock->ctx; - - if (proxy && ctx->pr.init) { - return ctx->pr.pack_raw(proxy, addr, packet, pkt_size, s_idx, c_idx, public, shsec, nonce, seq, payload, payload_size); - } else { - return ecp_pack(ctx, packet, pkt_size, s_idx, c_idx, public, shsec, nonce, seq, payload, payload_size); - } -} - ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *proxy, unsigned char *packet, size_t pkt_size) { unsigned char s_idx; unsigned char c_idx; @@ -1216,10 +1205,11 @@ ssize_t ecp_pld_send(ECPConnection *conn, unsigned char *payload, size_t payload ssize_t ecp_pld_send_wkey(ECPConnection *conn, ecp_seq_t *seq, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size) { unsigned char packet[ECP_MAX_PKT]; ECPSocket *sock = conn->sock; + ECPContext *ctx = sock->ctx; ECPNetAddr addr; ssize_t rv; - rv = ecp_proxy_pack(conn, &addr, seq, packet, ECP_MAX_PKT, s_idx, c_idx, payload, payload_size); + rv = ctx->pack(conn, &addr, seq, packet, ECP_MAX_PKT, s_idx, c_idx, payload, payload_size); if (rv < 0) return rv; #ifdef ECP_WITH_RBUF @@ -1233,10 +1223,11 @@ ssize_t ecp_pld_send_wkey(ECPConnection *conn, ecp_seq_t *seq, unsigned char s_i ssize_t ecp_pld_send_raw(ECPSocket *sock, ECPConnection *proxy, ECPNetAddr *addr, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size) { unsigned char packet[ECP_MAX_PKT]; + ECPContext *ctx = sock->ctx; ECPNetAddr _addr; ssize_t rv; - rv = ecp_proxy_pack_raw(sock, proxy, &_addr, packet, ECP_MAX_PKT, s_idx, c_idx, public, shsec, nonce, seq, payload, payload_size); + rv = ctx->pack_raw(sock, proxy, &_addr, packet, ECP_MAX_PKT, s_idx, c_idx, public, shsec, nonce, seq, payload, payload_size); if (rv < 0) return rv; return ecp_pkt_send(sock, proxy ? &_addr : addr, packet, rv); diff --git a/code/core/core.h b/code/core/core.h index 9cf3cf2..2dd7951 100644 --- a/code/core/core.h +++ b/code/core/core.h @@ -163,12 +163,6 @@ typedef struct ECPTimeIface { void (*sleep_ms) (unsigned int); } ECPTimeIface; -typedef struct ECPProxyIface { - int init; - ssize_t (*pack) (struct ECPConnection *conn, ECPNetAddr *addr, ecp_seq_t *seq, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size); - ssize_t (*pack_raw) (struct ECPConnection *proxy, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size); -} ECPProxyIface; - typedef struct ECPDHKey { ecp_dh_public_t public; ecp_dh_private_t private; @@ -220,7 +214,8 @@ typedef struct ECPContext { ECPHTableIface ht; ECPTransportIface tr; ECPTimeIface tm; - ECPProxyIface pr; + ssize_t (*pack) (struct ECPConnection *conn, ECPNetAddr *addr, ecp_seq_t *seq, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size); + ssize_t (*pack_raw) (struct ECPSocket *sock, struct ECPConnection *proxy, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size); ECPConnHandler *handler[ECP_MAX_CTYPE]; } ECPContext; @@ -312,9 +307,8 @@ int ecp_conn_dhkey_new_pub(ECPConnection *conn, unsigned char idx, unsigned char int ecp_conn_dhkey_get_curr(ECPConnection *conn, unsigned char *idx, unsigned char *public); ssize_t ecp_pack(ECPContext *ctx, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size); +ssize_t ecp_pack_raw(ECPSocket *sock, ECPConnection *proxy, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size); ssize_t ecp_conn_pack(ECPConnection *conn, ECPNetAddr *addr, ecp_seq_t *seq, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size); -ssize_t ecp_proxy_pack(ECPConnection *conn, ECPNetAddr *addr, ecp_seq_t *seq, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, unsigned char *payload, size_t payload_size); -ssize_t ecp_proxy_pack_raw(ECPSocket *sock, ECPConnection *proxy, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size, unsigned char s_idx, unsigned char c_idx, ecp_dh_public_t *public, ecp_aead_key_t *shsec, unsigned char *nonce, ecp_seq_t seq, unsigned char *payload, size_t payload_size); ssize_t ecp_pkt_handle(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *proxy, unsigned char *packet, size_t pkt_size); ssize_t ecp_pkt_send(ECPSocket *sock, ECPNetAddr *addr, unsigned char *packet, size_t pkt_size); |