aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2020-06-21 15:32:31 +0200
committerToni Uhlig <matzeton@googlemail.com>2020-06-21 15:32:31 +0200
commit46305df5903270d9b63652a1ce5fae2ee861a0e4 (patch)
tree9270c8e8697afd2d6451524e8c59e992029c4641
parent8cfdfdc4dec97710ae52aa8fb5efa5d162811114 (diff)
added RECV_FATAL_CALLBACK_ERROR for callback specific failured, RECV_FATAL is for internal failures
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--client.c6
-rw-r--r--common-event2.c6
-rw-r--r--protocol.c4
-rw-r--r--protocol.h1
-rw-r--r--server.c10
5 files changed, 15 insertions, 12 deletions
diff --git a/client.c b/client.c
index bdd0dd5..c8bb974 100644
--- a/client.c
+++ b/client.c
@@ -68,12 +68,12 @@ enum recv_return protocol_request_server_helo(struct connection * const state,
if (init_crypto_client(state, helo_pkt->client_rx_header, sizeof(helo_pkt->client_rx_header)) != 0) {
LOG(ERROR, "Client session keypair generation failed");
- return RECV_FATAL;
+ return RECV_FATAL_CALLBACK_ERROR;
}
if (ev_setup_generic_timer((struct ev_user_data *)state->user_data, PING_INTERVAL) != 0) {
LOG(ERROR, "Timer init failed");
- return RECV_FATAL;
+ return RECV_FATAL_CALLBACK_ERROR;
}
send_data(state);
@@ -113,7 +113,7 @@ enum recv_return protocol_request_ping(struct connection * const state,
}
if (ev_protocol_pong(state) != 0) {
- return RECV_FATAL;
+ return RECV_FATAL_CALLBACK_ERROR;
} else {
return RECV_SUCCESS;
}
diff --git a/common-event2.c b/common-event2.c
index bc631e7..7f60ba9 100644
--- a/common-event2.c
+++ b/common-event2.c
@@ -268,7 +268,7 @@ void ev_read_cb(struct bufferevent * bev, void * connection_state)
case RECV_SUCCESS:
break;
case RECV_FATAL:
- LOG(ERROR, "Callback Fatal");
+ LOG(ERROR, "Internal error");
ev_disconnect(c);
return;
case RECV_FATAL_UNAUTH:
@@ -283,6 +283,10 @@ void ev_read_cb(struct bufferevent * bev, void * connection_state)
LOG(ERROR, "Remote has a larger WINDOW_SIZE size than us.");
ev_disconnect(c);
return;
+ case RECV_FATAL_CALLBACK_ERROR:
+ LOG(ERROR, "Callback error");
+ ev_disconnect(c);
+ return;
case RECV_CORRUPT_PACKET:
LOG(ERROR, "Packet Corrupt");
ev_disconnect(c);
diff --git a/protocol.c b/protocol.c
index 940e0cd..ba3e2ed 100644
--- a/protocol.c
+++ b/protocol.c
@@ -73,9 +73,7 @@ static enum recv_return parse_protocol_timestamp(char const protocol_timestamp[P
char timestamp_sz[PROTOCOL_TIME_STRLEN + 1];
strncpy(timestamp_sz, protocol_timestamp, sizeof(timestamp_sz) - 1);
timestamp_sz[PROTOCOL_TIME_STRLEN] = '\0';
- if (strptime(timestamp_sz, "%a, %d %b %Y %T %z", dest) == NULL) {
- return RECV_FATAL;
- }
+ strptime(timestamp_sz, "%a, %d %b %Y %T %z", dest);
return RECV_SUCCESS;
}
diff --git a/protocol.h b/protocol.h
index 30619c9..92dcf21 100644
--- a/protocol.h
+++ b/protocol.h
@@ -162,6 +162,7 @@ enum recv_return {
RECV_FATAL_UNAUTH,
RECV_FATAL_CRYPTO_ERROR,
RECV_FATAL_REMOTE_WINDOW_SIZE,
+ RECV_FATAL_CALLBACK_ERROR,
RECV_CORRUPT_PACKET,
RECV_BUFFER_NEED_MORE_DATA,
RECV_CALLBACK_NOT_IMPLEMENTED
diff --git a/server.c b/server.c
index 5e1558d..7247371 100644
--- a/server.c
+++ b/server.c
@@ -68,16 +68,16 @@ enum recv_return protocol_request_client_auth(struct connection * const state,
log_bin2hex_sodium(NOTICE, "Client AUTH with PublicKey", auth_pkt->client_publickey, sizeof(auth_pkt->client_publickey));
if (init_crypto_server(state, auth_pkt->server_rx_header, sizeof(auth_pkt->server_rx_header)) != 0) {
LOG(ERROR, "Client session keypair generation failed");
- return RECV_FATAL;
+ return RECV_FATAL_CRYPTO_ERROR;
}
if (ev_protocol_server_helo(state, "Welcome.") != 0) {
LOG(ERROR, "Server AUTH response failed");
- return RECV_FATAL;
+ return RECV_FATAL_CALLBACK_ERROR;
}
if (ev_setup_generic_timer((struct ev_user_data *)state->user_data, PING_INTERVAL) != 0) {
LOG(ERROR, "Timer init failed");
- return RECV_FATAL;
+ return RECV_FATAL_CALLBACK_ERROR;
}
state->state = CONNECTION_AUTH_SUCCESS;
@@ -108,7 +108,7 @@ enum recv_return protocol_request_data(struct connection * const state,
recv_data(data_pkt->payload, data_pkt->header.body_size);
snprintf(response, sizeof(response), "DATA OK: RECEIVED %u BYTES", data_pkt->header.body_size);
if (ev_protocol_data(state, (uint8_t *)response, sizeof(response)) != 0) {
- return RECV_FATAL;
+ return RECV_FATAL_CALLBACK_ERROR;
}
return RECV_SUCCESS;
}
@@ -130,7 +130,7 @@ enum recv_return protocol_request_ping(struct connection * const state,
}
if (ev_protocol_pong(state) != 0) {
- return RECV_FATAL;
+ return RECV_FATAL_CALLBACK_ERROR;
} else {
return RECV_SUCCESS;
}