Skip to content

Commit

Permalink
Merge PR #38 'pinheadmz/clearnet2'
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Sep 24, 2020
2 parents b5efe52 + 522f0b9 commit 95da9e3
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 75 deletions.
21 changes: 12 additions & 9 deletions src/addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ hsk_addr_from_string(hsk_addr_t *addr, const char *src, uint16_t port) {

uint16_t sin_port = port;

if (port && port_s) {
if (port_s) {
int i = 0;
uint32_t word = 0;
char *s = port_s;
Expand All @@ -396,8 +396,10 @@ hsk_addr_from_string(hsk_addr_t *addr, const char *src, uint16_t port) {
}

sin_port = (uint16_t)word;
} else if (!port && port_s) {
return false;
} else if (!port) {
sin_port = at ? HSK_BRONTIDE_PORT : HSK_PORT;
} else {
sin_port = port;
}

uint8_t sin_addr[16];
Expand Down Expand Up @@ -446,8 +448,7 @@ hsk_addr_to_string(
if (!port)
port = fb;

// XXX Not thread safe.
static char tmp[HSK_MAX_HOST];
char tmp[HSK_MAX_HOST];

if (af == AF_INET6) {
assert(len + need < HSK_MAX_HOST);
Expand Down Expand Up @@ -487,8 +488,7 @@ hsk_addr_to_full(
char b32[54];
hsk_base32_encode(addr->key, 33, b32, false);

// XXX Not thread safe.
static char tmp[HSK_MAX_HOST];
char tmp[HSK_MAX_HOST];
sprintf(tmp, "%s@%s", b32, dst);
strcpy(dst, tmp);

Expand All @@ -515,8 +515,7 @@ hsk_addr_to_at(const hsk_addr_t *addr, char *dst, size_t dst_len, uint16_t fb) {
if (!port)
port = fb;

// XXX Not thread safe.
static char tmp[HSK_MAX_HOST];
char tmp[HSK_MAX_HOST];
sprintf(tmp, "%s@%u", dst, port);
strcpy(dst, tmp);
}
Expand Down Expand Up @@ -940,7 +939,11 @@ hsk_addr_print(const hsk_addr_t *addr, const char *prefix) {
char host[HSK_MAX_HOST];
assert(hsk_addr_to_string(addr, host, HSK_MAX_HOST, HSK_BRONTIDE_PORT));

char b32[54];
hsk_base32_encode(addr->key, 33, b32, false);

printf("%saddr\n", prefix);
printf("%skey=%s\n", prefix, b32);
printf("%s type=%d\n", prefix, addr->type);
printf("%s host=%s\n", prefix, host);
}
Expand Down
2 changes: 1 addition & 1 deletion src/addrmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ hsk_addrman_init(hsk_addrman_t *am, const hsk_timedata_t *td) {
const char **seed;
for (seed = hsk_seeds; *seed; seed++) {
hsk_addr_t addr;
assert(hsk_addr_from_string(&addr, *seed, HSK_BRONTIDE_PORT));
assert(hsk_addr_from_string(&addr, *seed, 0));
assert(hsk_addrman_add_addr(am, &addr));
}

Expand Down
Loading

0 comments on commit 95da9e3

Please sign in to comment.