Skip to content

Commit

Permalink
server: fix uninitialized listen address
Browse files Browse the repository at this point in the history
Signed-off-by: hexian000 <[email protected]>
  • Loading branch information
hexian000 committed Jan 6, 2024
1 parent 25ab56b commit 6b12186
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ Rendezvous mode may be useful for accessing servers behind NAT. The rendezvous s

rendezvous_server : server : client = 1 : 1 : n

Peers should be all IPv4 or all IPv6.

## Tunables

*kcptun-libev works out of the box. In most cases, the default options are recommended.*
Expand Down
3 changes: 2 additions & 1 deletion src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ struct pktconn {
struct pktqueue *queue;
int fd;
int domain;
bool connected;
union sockaddr_max kcp_connect;
ev_tstamp last_send_time;
ev_tstamp last_recv_time;
ev_tstamp inflight_ping;

bool listened : 1;
bool connected : 1;
union sockaddr_max server_addr[2];
union sockaddr_max rendezvous_server;
};
Expand Down
11 changes: 8 additions & 3 deletions src/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ ss0_on_listen(struct server *restrict s, struct msgframe *restrict msg)
LOG_F(DEBUG, "rendezvous listen: (%s, %s)", addr1_str,
addr2_str);
}
s->pkt.listened = true;
return true;
}

Expand All @@ -657,19 +658,23 @@ ss0_on_connect(struct server *restrict s, struct msgframe *restrict msg)
return false;
}
if (LOGLEVEL(INFO)) {
char caddr1_str[64], caddr2_str[64];
format_sa(&addr.sa, caddr1_str, sizeof(caddr1_str));
format_sa(&msg->addr.sa, caddr2_str, sizeof(caddr2_str));
char saddr1_str[64], saddr2_str[64];
format_sa(
&s->pkt.server_addr[0].sa, saddr1_str,
sizeof(saddr1_str));
format_sa(
&s->pkt.server_addr[1].sa, saddr2_str,
sizeof(saddr2_str));
char caddr1_str[64], caddr2_str[64];
format_sa(&addr.sa, caddr1_str, sizeof(caddr1_str));
format_sa(&msg->addr.sa, caddr2_str, sizeof(caddr2_str));
LOG_F(INFO, "rendezvous connect: (%s, %s) -> (%s, %s)",
caddr1_str, caddr2_str, saddr1_str, saddr2_str);
}
if (!s->pkt.listened) {
LOGE("rendezvous connect: no server available");
return true;
}

/* notify the server */
unsigned char b[INET6ADDR_LENGTH + INET6ADDR_LENGTH];
Expand Down

0 comments on commit 6b12186

Please sign in to comment.