21
mud.c
21
mud.c
@@ -123,11 +123,11 @@ struct mud_packet {
|
|||||||
unsigned char time[MUD_U48_SIZE];
|
unsigned char time[MUD_U48_SIZE];
|
||||||
unsigned char kiss[MUD_KISS_SIZE];
|
unsigned char kiss[MUD_KISS_SIZE];
|
||||||
struct mud_addr addr;
|
struct mud_addr addr;
|
||||||
|
unsigned char state;
|
||||||
unsigned char code;
|
unsigned char code;
|
||||||
} hdr;
|
} hdr;
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
unsigned char state;
|
|
||||||
struct mud_public public;
|
struct mud_public public;
|
||||||
unsigned char aes;
|
unsigned char aes;
|
||||||
} conf;
|
} conf;
|
||||||
@@ -662,10 +662,7 @@ mud_set_state(struct mud *mud, struct sockaddr *peer, enum mud_state state)
|
|||||||
if (!path)
|
if (!path)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (path->state != state) {
|
path->state = state;
|
||||||
path->state = state;
|
|
||||||
path->conf.remote = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1031,12 +1028,12 @@ mud_packet_send(struct mud *mud, enum mud_packet_code code,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
packet->hdr.state = (unsigned char)path->state;
|
||||||
packet->hdr.code = (unsigned char)code;
|
packet->hdr.code = (unsigned char)code;
|
||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case mud_conf:
|
case mud_conf:
|
||||||
size = sizeof(packet->data.conf);
|
size = sizeof(packet->data.conf);
|
||||||
packet->data.conf.state = (unsigned char)path->state;
|
|
||||||
memcpy(&packet->data.conf.public.local, &mud->crypto.public.local,
|
memcpy(&packet->data.conf.public.local, &mud->crypto.public.local,
|
||||||
sizeof(mud->crypto.public.local));
|
sizeof(mud->crypto.public.local));
|
||||||
memcpy(&packet->data.conf.public.remote, &mud->crypto.public.remote,
|
memcpy(&packet->data.conf.public.remote, &mud->crypto.public.remote,
|
||||||
@@ -1072,7 +1069,7 @@ mud_kiss_path(struct mud *mud, unsigned char *kiss)
|
|||||||
for (unsigned i = 0; i < mud->count; i++) {
|
for (unsigned i = 0; i < mud->count; i++) {
|
||||||
struct mud_path *path = &mud->paths[i];
|
struct mud_path *path = &mud->paths[i];
|
||||||
|
|
||||||
if (memcmp(path->conf.kiss, kiss, sizeof(path->conf.kiss)))
|
if (memcmp(path->kiss, kiss, sizeof(path->kiss)))
|
||||||
path->state = MUD_EMPTY;
|
path->state = MUD_EMPTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1120,11 +1117,8 @@ mud_packet_recv(struct mud *mud, struct mud_path *path,
|
|||||||
{
|
{
|
||||||
struct mud_packet *packet = (struct mud_packet *)data;
|
struct mud_packet *packet = (struct mud_packet *)data;
|
||||||
|
|
||||||
memcpy(path->conf.kiss, packet->hdr.kiss,
|
memcpy(path->kiss, packet->hdr.kiss, sizeof(path->kiss));
|
||||||
sizeof(path->conf.kiss));
|
memcpy(mud->remote.kiss, packet->hdr.kiss, sizeof(mud->remote.kiss));
|
||||||
|
|
||||||
memcpy(mud->remote.kiss, packet->hdr.kiss,
|
|
||||||
sizeof(path->conf.kiss));
|
|
||||||
|
|
||||||
if (memcmp(packet->hdr.addr.v6, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12)) {
|
if (memcmp(packet->hdr.addr.v6, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12)) {
|
||||||
path->r_addr.ss_family = AF_INET6;
|
path->r_addr.ss_family = AF_INET6;
|
||||||
@@ -1143,6 +1137,8 @@ mud_packet_recv(struct mud *mud, struct mud_path *path,
|
|||||||
if (!mud->peer.set)
|
if (!mud->peer.set)
|
||||||
mud_kiss_path(mud, mud->remote.kiss);
|
mud_kiss_path(mud, mud->remote.kiss);
|
||||||
|
|
||||||
|
path->state = (enum mud_state)packet->hdr.state;
|
||||||
|
|
||||||
switch (packet->hdr.code) {
|
switch (packet->hdr.code) {
|
||||||
case mud_conf:
|
case mud_conf:
|
||||||
path->conf.remote = 1;
|
path->conf.remote = 1;
|
||||||
@@ -1165,7 +1161,6 @@ mud_packet_recv(struct mud *mud, struct mud_path *path,
|
|||||||
mud_keyx(mud, packet->data.conf.public.local,
|
mud_keyx(mud, packet->data.conf.public.local,
|
||||||
packet->data.conf.aes);
|
packet->data.conf.aes);
|
||||||
}
|
}
|
||||||
path->state = (enum mud_state)packet->data.conf.state;
|
|
||||||
mud_packet_send(mud, mud_conf, path, now, MSG_CONFIRM);
|
mud_packet_send(mud, mud_conf, path, now, MSG_CONFIRM);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
2
mud.h
2
mud.h
@@ -18,10 +18,10 @@ enum mud_state {
|
|||||||
struct mud_path {
|
struct mud_path {
|
||||||
enum mud_state state;
|
enum mud_state state;
|
||||||
struct sockaddr_storage local_addr, addr, r_addr;
|
struct sockaddr_storage local_addr, addr, r_addr;
|
||||||
|
unsigned char kiss[MUD_KISS_SIZE];
|
||||||
struct {
|
struct {
|
||||||
uint64_t send_time;
|
uint64_t send_time;
|
||||||
int remote;
|
int remote;
|
||||||
unsigned char kiss[MUD_KISS_SIZE];
|
|
||||||
} conf;
|
} conf;
|
||||||
uint64_t send_max;
|
uint64_t send_max;
|
||||||
uint64_t send_max_time;
|
uint64_t send_max_time;
|
||||||
|
|||||||
Reference in New Issue
Block a user