diff --git a/daemon/call.c b/daemon/call.c index 78f13e46e..6746fe265 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -1153,6 +1153,17 @@ static void relays_cache_init(struct relays_cache *c) { c->array_ptrs[1] = c->relays_B; } +int relays_cache_want_ports(struct relays_cache *c, int portA, int portB, struct call *call) { + if (c->relays_open + 2 > ARRAY_SIZE(c->relays_A)) + return -1; + if (get_consecutive_ports(&c->relays_A[c->relays_open], 2, portA, call)) + return -1; + if (get_consecutive_ports(&c->relays_B[c->relays_open], 2, portB, call)) + return -1; + c->relays_open += 2; + return 0; +} + static int relays_cache_get_ports(struct relays_cache *c, int num, struct call *call) { num *= 2; if (c->relays_open >= num) diff --git a/daemon/call.h b/daemon/call.h index 1155d9993..085108806 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -166,6 +166,7 @@ struct callstream *callstream_new(struct call *ca, int num); void callstream_init(struct callstream *s, struct relays_cache *); void kernelize(struct callstream *c); int call_stream_address(char *o, struct peer *p, enum stream_address_format format, int *len); +int relays_cache_want_ports(struct relays_cache *c, int portA, int portB, struct call *call); static inline char *call_strdup(struct call *c, const char *s) { char *r; @@ -176,19 +177,23 @@ static inline char *call_strdup(struct call *c, const char *s) { mutex_unlock(&c->chunk_lock); return r; } -static inline str *call_str_cpy(struct call *c, str *out, const str *in) { +static inline str *call_str_cpy_len(struct call *c, str *out, const char *in, int len) { if (!in) { *out = STR_NULL; return out; } - *out = *in; - if (!in->s) - return out; mutex_lock(&c->chunk_lock); - out->s = g_string_chunk_insert_len(c->chunk, in->s, in->len); + out->s = g_string_chunk_insert_len(c->chunk, in, len); mutex_unlock(&c->chunk_lock); + out->len = len; return out; } +static inline str *call_str_cpy(struct call *c, str *out, const str *in) { + return call_str_cpy_len(c, out, in ? in->s : NULL, in ? in->len : 0); +} +static inline str *call_str_cpy_c(struct call *c, str *out, const char *in) { + return call_str_cpy_len(c, out, in, in ? strlen(in) : 0); +} static inline str *call_str_dup(struct call *c, const str *in) { str *out; mutex_lock(&c->chunk_lock);