diff --git a/core/main.c b/core/main.c index 588f364b..7f5adf21 100644 --- a/core/main.c +++ b/core/main.c @@ -10,7 +10,7 @@ #define CORE_FILE "core.json" -int main(int argc, char **argv) +int main(void) { // test ASAN works -_- // int test[3] = {0}; @@ -56,7 +56,7 @@ int main(int argc, char **argv) loadStaticTunnelsIntoCore(); // [Parse ConfigFiles] - // TODO this currently runs only 1 config file + // TODO (config file) this currently runs only 1 config file { c_foreach(k, vec_config_path_t, getCoreSettings()->config_paths) { diff --git a/tunnels/adapters/connector/connector.c b/tunnels/adapters/connector/connector.c index 60d2f290..b7d17433 100644 --- a/tunnels/adapters/connector/connector.c +++ b/tunnels/adapters/connector/connector.c @@ -34,7 +34,7 @@ tunnel_t *newConnector(node_instance_context_t *instance_info) "src_context->address", "dest_context->address"); - if (state->dest_addr.status == dvs_empty) + if (state->dest_addr.status == kDvsEmpty) { LOGF("JSON Error: Connector->settings->address (string field) : The vaule was empty or invalid"); return NULL; @@ -44,12 +44,12 @@ tunnel_t *newConnector(node_instance_context_t *instance_info) "src_context->port", "dest_context->port"); - if (state->dest_port.status == dvs_empty) + if (state->dest_port.status == kDvsEmpty) { LOGF("JSON Error: Connector->settings->port (number field) : The vaule was empty or invalid"); return NULL; } - if(state->dest_addr.status == dvs_constant){ + if(state->dest_addr.status == kDvsConstant){ state->dest_atype = getHostAddrType(state->dest_addr.value_ptr); state->dest_domain_len = strlen(state->dest_addr.value_ptr); } diff --git a/tunnels/adapters/connector/tcp.c b/tunnels/adapters/connector/tcp.c index a12dd241..e6ebda2a 100644 --- a/tunnels/adapters/connector/tcp.c +++ b/tunnels/adapters/connector/tcp.c @@ -248,7 +248,7 @@ void connectorUpStream(tunnel_t *self, context_t *c) else { final_ctx.atype = state->dest_atype; - if (state->dest_atype == SAT_DOMAINNAME) + if (state->dest_atype == kSatDomainName) { final_ctx.domain = malloc(state->dest_domain_len + 1); memcpy(final_ctx.domain, state->dest_addr.value_ptr, state->dest_domain_len + 1); @@ -270,7 +270,7 @@ void connectorUpStream(tunnel_t *self, context_t *c) // sockaddr_set_ipport(&(final_ctx.addr), "127.0.0.1", 443); LOGD("Connector: initiating tcp connection"); - if (final_ctx.atype == SAT_DOMAINNAME) + if (final_ctx.atype == kSatDomainName) { if (!final_ctx.resolved) { diff --git a/tunnels/adapters/connector/udp.c b/tunnels/adapters/connector/udp.c index dc37341d..bb16e0fa 100644 --- a/tunnels/adapters/connector/udp.c +++ b/tunnels/adapters/connector/udp.c @@ -2,6 +2,18 @@ #include "types.h" #include "utils/sockutils.h" +static void cleanup(connector_con_state_t *cstate) +{ + connector_state_t *state = STATE(cstate->tunnel); + if (state->dest_addr.status == cdvs_constant) + { + + }else if (state->dest_addr.status > cdvs_constant){ + free(cstate->line->dest_ctx) + } + + free(cstate); +} static void onUdpRecv(hio_t *io, void *buf, int readbytes) { connector_con_state_t *cstate = (connector_con_state_t *) (hevent_userdata(io)); @@ -19,11 +31,11 @@ static void onUdpRecv(hio_t *io, void *buf, int readbytes) if (destaddr->sa_family == AF_INET6) { - atype = SAT_IPV6; + atype = kSatIpV6; } else { - atype = SAT_IPV4; + atype = kSatIpV4; } if (! cstate->established) @@ -52,11 +64,11 @@ void connectorPacketUpStream(tunnel_t *self, context_t *c) if (c->payload != NULL) { - int bytes = bufLen(c->payload); + unsigned int bytes = bufLen(c->payload); if (hio_is_closed(cstate->io)) { - free(CSTATE(c)); + cleanup(CSTATE(c)); CSTATE_MUT(c) = NULL; DISCARD_CONTEXT(c); goto fail; @@ -97,7 +109,7 @@ void connectorPacketUpStream(tunnel_t *self, context_t *c) if (sockfd < 0) { LOGE("Connector: socket fd < 0"); - free(CSTATE(c)); + cleanup(CSTATE(c)); CSTATE_MUT(c) = NULL; goto fail; } @@ -124,7 +136,7 @@ void connectorPacketUpStream(tunnel_t *self, context_t *c) hio_setcb_read(upstream_io, onUdpRecv); hio_read(upstream_io); - socket_context_t resolved_dest_context = {0}; + socket_context_t* resolved_dest_context; // fill the resolved_dest_context address based on settings { socket_context_t *src_ctx = &(c->line->src_ctx); @@ -132,18 +144,23 @@ void connectorPacketUpStream(tunnel_t *self, context_t *c) connector_state_t *state = STATE(self); if (state->dest_addr.status == cdvs_from_source) - copySocketContextAddr(&resolved_dest_context, &src_ctx); + { + resolved_dest_context = src_ctx; + // copySocketContextAddr(&resolved_dest_context, &src_ctx); + } else if (state->dest_addr.status == cdvs_from_dest) - copySocketContextAddr(&resolved_dest_context, &dest_ctx); + { + resolved_dest_context = dest_ctx; + // copySocketContextAddr(&resolved_dest_context, &dest_ctx); + } else { resolved_dest_context.atype = state->dest_atype; - if (state->dest_atype == SAT_DOMAINNAME) + if (state->dest_atype == kSatDomainName) { - resolved_dest_context.domain = state->dest_addr.value_ptr; - resolved_dest_context.domain_len = state->dest_domain_len; - resolved_dest_context.domain_is_constant_memory = true; - resolved_dest_context.resolved = false; + resolved_dest_context.domain = state->dest_addr.value_ptr; + resolved_dest_context.domain_len = state->dest_domain_len; + resolved_dest_context.resolved = false; } else sockaddr_set_ip(&(resolved_dest_context.addr), state->dest_addr.value_ptr); @@ -157,14 +174,14 @@ void connectorPacketUpStream(tunnel_t *self, context_t *c) sockaddr_set_port(&(resolved_dest_context.addr), state->dest_port.value); } - if (resolved_dest_context.atype == SAT_DOMAINNAME) + if (resolved_dest_context.atype == kSatDomainName) { if (! resolved_dest_context.resolved) { if (! connectorResolvedomain(&(resolved_dest_context))) { free(resolved_dest_context.domain); - free(CSTATE(c)); + cleanup(CSTATE(c)); CSTATE_MUT(c) = NULL; DISCARD_CONTEXT(c); goto fail; @@ -180,7 +197,7 @@ void connectorPacketUpStream(tunnel_t *self, context_t *c) { hio_t *io = cstate->io; hevent_set_userdata(io, NULL); - free(CSTATE(c)); + cleanup(CSTATE(c)); CSTATE_MUT(c) = NULL; destroyContext(c); hio_close(io); @@ -198,7 +215,7 @@ void connectorPacketDownStream(tunnel_t *self, context_t *c) { hio_t *io = CSTATE(c)->io; hevent_set_userdata(io, NULL); - free(CSTATE(c)); + cleanup(CSTATE(c)); CSTATE_MUT(c) = NULL; } self->dw->downStream(self->dw, c); diff --git a/tunnels/adapters/tcp_connector/tcp_connector.c b/tunnels/adapters/tcp_connector/tcp_connector.c index 3a196c5c..db7e711d 100644 --- a/tunnels/adapters/tcp_connector/tcp_connector.c +++ b/tunnels/adapters/tcp_connector/tcp_connector.c @@ -247,7 +247,7 @@ void tcpConnectorUpStream(tunnel_t *self, context_t *c) else { final_ctx.atype = state->dest_atype; - if (state->dest_atype == SAT_DOMAINNAME) + if (state->dest_atype == kSatDomainName) { final_ctx.domain = malloc(state->dest_domain_len + 1); memcpy(final_ctx.domain, state->dest_addr.value_ptr, state->dest_domain_len + 1); @@ -269,7 +269,7 @@ void tcpConnectorUpStream(tunnel_t *self, context_t *c) // sockaddr_set_ipport(&(final_ctx.addr), "127.0.0.1", 443); LOGD("TcpConnector: initiating connection"); - if (final_ctx.atype == SAT_DOMAINNAME) + if (final_ctx.atype == kSatDomainName) { if (!final_ctx.resolved) { @@ -430,7 +430,7 @@ tunnel_t *newTcpConnector(node_instance_context_t *instance_info) "src_context->address", "dest_context->address"); - if (state->dest_addr.status == dvs_empty) + if (state->dest_addr.status == kDvsEmpty) { LOGF("JSON Error: TcpConnector->settings->address (string field) : The vaule was empty or invalid"); return NULL; @@ -440,12 +440,12 @@ tunnel_t *newTcpConnector(node_instance_context_t *instance_info) "src_context->port", "dest_context->port"); - if (state->dest_port.status == dvs_empty) + if (state->dest_port.status == kDvsEmpty) { LOGF("JSON Error: TcpConnector->settings->port (number field) : The vaule was empty or invalid"); return NULL; } - if (state->dest_addr.status == dvs_constant) + if (state->dest_addr.status == kDvsConstant) { state->dest_atype = getHostAddrType(state->dest_addr.value_ptr); state->dest_domain_len = strlen(state->dest_addr.value_ptr); diff --git a/tunnels/adapters/tcp_listener/tcp_listener.c b/tunnels/adapters/tcp_listener/tcp_listener.c index edc2f8cb..607b7dbf 100644 --- a/tunnels/adapters/tcp_listener/tcp_listener.c +++ b/tunnels/adapters/tcp_listener/tcp_listener.c @@ -333,7 +333,7 @@ void on_inbound_connected(hevent_t *ev) // sockaddr_set_port(&(line->src_ctx.addr), data->real_localport == 0 ? sockaddr_port((sockaddr_u *)hio_localaddr(io)) : data->real_localport); sockaddr_set_port(&(line->src_ctx.addr), data->real_localport); - line->src_ctx.atype = line->src_ctx.addr.sa.sa_family == AF_INET ? SAT_IPV4 : SAT_IPV6; + line->src_ctx.atype = line->src_ctx.addr.sa.sa_family == AF_INET ? kSatIpV4 : kSatIpV6; hevent_set_userdata(io, cstate); struct sockaddr log_localaddr = *hio_localaddr(io); diff --git a/tunnels/server/trojan/socks/trojan_socks_server.c b/tunnels/server/trojan/socks/trojan_socks_server.c index 1187de57..aa24ae74 100644 --- a/tunnels/server/trojan/socks/trojan_socks_server.c +++ b/tunnels/server/trojan/socks/trojan_socks_server.c @@ -57,20 +57,20 @@ static void makeUdpPacketAddress(context_t *c) shiftl(c->payload, 2); // port writeUI16(c->payload, port); - if (c->line->dest_ctx.atype == SAT_IPV6) + if (c->line->dest_ctx.atype == kSatIpV6) { shiftl(c->payload, 16); writeRaw(c->payload, &(c->line->dest_ctx.addr.sin6.sin6_addr), 16); shiftl(c->payload, 1); - writeUI8(c->payload, SAT_IPV6); + writeUI8(c->payload, kSatIpV6); } - else if (c->line->dest_ctx.atype == SAT_DOMAINNAME) + else if (c->line->dest_ctx.atype == kSatDomainName) { shiftl(c->payload, 16); writeRaw(c->payload, &(c->line->dest_ctx.addr.sin6.sin6_addr), 16); shiftl(c->payload, 1); - writeUI8(c->payload, SAT_IPV6); + writeUI8(c->payload, kSatIpV6); } else { @@ -78,7 +78,7 @@ static void makeUdpPacketAddress(context_t *c) writeRaw(c->payload, &(c->line->dest_ctx.addr.sin.sin_addr), 4); shiftl(c->payload, 1); - writeUI8(c->payload, SAT_IPV4); + writeUI8(c->payload, kSatIpV4); } } @@ -318,7 +318,7 @@ static bool processUdp(tunnel_t *self, trojan_socks_server_con_state_t *cstate, { case TROJANATYP_IPV4: dest->addr.sa.sa_family = AF_INET; - dest->atype = SAT_IPV4; + dest->atype = kSatIpV4; memcpy(&(dest->addr.sin.sin_addr), rawBuf(c->payload), 4); shiftr(c->payload, 4); if (!cstate->first_sent) @@ -326,7 +326,7 @@ static bool processUdp(tunnel_t *self, trojan_socks_server_con_state_t *cstate, break; case TROJANATYP_DOMAINNAME: - dest->atype = SAT_DOMAINNAME; + dest->atype = kSatDomainName; // size_t addr_len = (unsigned char)(rawBuf(c->payload)[0]); shiftr(c->payload, 1); if (dest->domain == NULL) @@ -343,7 +343,7 @@ static bool processUdp(tunnel_t *self, trojan_socks_server_con_state_t *cstate, break; case TROJANATYP_IPV6: - dest->atype = SAT_IPV6; + dest->atype = kSatIpV6; dest->addr.sa.sa_family = AF_INET6; memcpy(&(dest->addr.sin.sin_addr), rawBuf(c->payload), 16); shiftr(c->payload, 16); diff --git a/ww/basic_types.h b/ww/basic_types.h index 9e233f6d..fbe070ce 100644 --- a/ww/basic_types.h +++ b/ww/basic_types.h @@ -76,17 +76,17 @@ typedef struct api_result_s enum domain_strategy { - ds_invalid, - ds_prefer_ipv4, - ds_prefer_ipv6, - ds_ipv4_only, - ds_ipv6_only + kDsInvalid, + kDsPreferIpV4, + kDsPreferIpV6, + kDsOnlyIpV4, + kDsOnlyIpV6 }; enum dynamic_value_status { - dvs_empty = 0x0, - dvs_constant, + kDvsEmpty = 0x0, + kDvsConstant, }; typedef struct dynamic_value_s { @@ -98,15 +98,15 @@ typedef struct dynamic_value_s enum socket_address_cmd { - SAC_CONNECT = 0X1, - SAC_ASSOCIATE = 0X3, + kSacConnect = 0X1, + kSacAssociate = 0X3, }; enum socket_address_type { - SAT_IPV4 = 0X1, - SAT_DOMAINNAME = 0X3, - SAT_IPV6 = 0X4, + kSatIpV4 = 0X1, + kSatDomainName = 0X3, + kSatIpV6 = 0X4, }; // all data we need to connect to somewhere @@ -117,7 +117,6 @@ typedef struct socket_context_s enum socket_address_type atype; char *domain; unsigned int *domain_len; - bool domain_is_constant_memory; bool resolved; sockaddr_u addr; diff --git a/ww/shiftbuffer.c b/ww/shiftbuffer.c index 3dde1b65..60d39fc8 100644 --- a/ww/shiftbuffer.c +++ b/ww/shiftbuffer.c @@ -3,24 +3,24 @@ #include // for assert #include //cel,log2,pow -extern unsigned int lCap(shift_buffer_t *self); -extern unsigned int rCap(shift_buffer_t *self); -extern unsigned int bufLen(shift_buffer_t *self); -extern void setLen(shift_buffer_t *self, unsigned int bytes); -extern void reserve(shift_buffer_t *self, unsigned int bytes); -extern void consume(shift_buffer_t *self, unsigned int bytse); -extern void shiftl(shift_buffer_t *self, unsigned int bytes); -extern void shiftr(shift_buffer_t *self, unsigned int bytes); -extern const void *rawBuf(shift_buffer_t *self); +extern unsigned int lCap(shift_buffer_t *self); +extern unsigned int rCap(shift_buffer_t *self); +extern unsigned int bufLen(shift_buffer_t *self); +extern void setLen(shift_buffer_t *self, unsigned int bytes); +extern void reserve(shift_buffer_t *self, unsigned int bytes); +extern void consume(shift_buffer_t *self, unsigned int bytes); +extern void shiftl(shift_buffer_t *self, unsigned int bytes); +extern void shiftr(shift_buffer_t *self, unsigned int bytes); +extern const void *rawBuf(shift_buffer_t *self); extern unsigned char *rawBufMut(shift_buffer_t *self); -extern void writeRaw(shift_buffer_t *restrict self, const void *restrict buffer, unsigned int len); -extern void writeI32(shift_buffer_t *self, int32_t data); -extern void writeUI32(shift_buffer_t *self, uint32_t data); -extern void writeI16(shift_buffer_t *self, int16_t data); -extern void writeUI16(shift_buffer_t *self, uint16_t data); -extern void writeUI8(shift_buffer_t *self, uint8_t data); -extern void readUI8(shift_buffer_t *self, uint8_t *dest); -extern void readUI16(shift_buffer_t *self, uint16_t *dest); +extern void writeRaw(shift_buffer_t *restrict self, const void *restrict buffer, unsigned int len); +extern void writeI32(shift_buffer_t *self, int32_t data); +extern void writeUI32(shift_buffer_t *self, uint32_t data); +extern void writeI16(shift_buffer_t *self, int16_t data); +extern void writeUI16(shift_buffer_t *self, uint16_t data); +extern void writeUI8(shift_buffer_t *self, uint8_t data); +extern void readUI8(shift_buffer_t *self, uint8_t *dest); +extern void readUI16(shift_buffer_t *self, uint16_t *dest); void destroyShiftBuffer(shift_buffer_t *self) { @@ -41,7 +41,7 @@ shift_buffer_t *newShiftBuffer(unsigned int pre_cap) unsigned int real_cap = pre_cap * 2; shift_buffer_t *self = malloc(sizeof(shift_buffer_t)); - self->pbuf = malloc(real_cap); + self->pbuf = malloc(real_cap); if (real_cap > 0) // map the virtual memory page to physical memory { @@ -53,12 +53,12 @@ shift_buffer_t *newShiftBuffer(unsigned int pre_cap) } while (i < real_cap); } - self->lenpos = pre_cap; - self->curpos = pre_cap; - self->cap = pre_cap; + self->lenpos = pre_cap; + self->curpos = pre_cap; + self->cap = pre_cap; self->full_cap = real_cap; - self->refc = malloc(sizeof(unsigned int)); - *(self->refc) = 1; + self->refc = malloc(sizeof(unsigned int)); + *(self->refc) = 1; return self; } @@ -69,7 +69,7 @@ shift_buffer_t *newShadowShiftBuffer(shift_buffer_t *owner) // keep it for later use *(owner->refc) += 1; shift_buffer_t *shadow = malloc(sizeof(shift_buffer_t)); - *shadow = *owner; + *shadow = *owner; return shadow; } @@ -80,9 +80,9 @@ void reset(shift_buffer_t *self, unsigned int cap) { free(self->pbuf); unsigned int real_cap = cap * 2; - self->pbuf = malloc(real_cap); - self->cap = cap; - self->full_cap = real_cap; + self->pbuf = malloc(real_cap); + self->cap = cap; + self->full_cap = real_cap; } self->lenpos = self->cap; self->curpos = self->cap; @@ -96,36 +96,41 @@ void expand(shift_buffer_t *self, unsigned int increase) { // LOGF("Expanding a shiftbuffer while it has refs is false assumption!"); // assert(false); - const unsigned int realcap = self->full_cap; - unsigned int new_realcap = pow(2, ceil(log2((float)(realcap * 2) + (increase * 2)))); + const unsigned int realcap = self->full_cap; + unsigned int new_realcap = (unsigned int) pow(2, ceil(log2((realcap * 2) + (increase * 2)))); // detach! *(self->refc) -= 1; - self->refc = malloc(sizeof(unsigned int)); + self->refc = malloc(sizeof(unsigned int)); *(self->refc) = 1; char *old_buf = self->pbuf; - self->pbuf = malloc(new_realcap); + self->pbuf = malloc(new_realcap); unsigned int dif = (new_realcap / 2) - self->cap; if (keep) + { memcpy(&(self->pbuf[dif]), &(old_buf[0]), realcap); + } free(old_buf); self->curpos += dif; self->lenpos += dif; - self->cap = new_realcap / 2; + self->cap = new_realcap / 2; self->full_cap = new_realcap; } else { - const unsigned int realcap = self->cap * 2; - unsigned int new_realcap = pow(2, ceil(log2((float)(realcap * 2) + (increase * 2)))); + const unsigned int realcap = self->cap * 2; + unsigned int new_realcap = (unsigned int) pow(2, ceil(log2((realcap * 2) + (increase * 2)))); // #ifdef DEBUG - // LOGW("Allocated more memory! oldcap = %zu , increase = %zu , newcap = %zu", self->cap * 2, increase, new_realcap); + // LOGW("Allocated more memory! oldcap = %zu , increase = %zu , newcap = %zu", self->cap * 2, increase, + // new_realcap); // #endif if (keep) + { self->pbuf = realloc(self->pbuf, new_realcap); + } else { free(self->pbuf); @@ -134,7 +139,7 @@ void expand(shift_buffer_t *self, unsigned int increase) unsigned int dif = (new_realcap / 2) - self->cap; self->curpos += dif; self->lenpos += dif; - self->cap = new_realcap / 2; + self->cap = new_realcap / 2; self->full_cap = new_realcap; } } diff --git a/ww/shiftbuffer.h b/ww/shiftbuffer.h index 1cd3e726..ca02f7b1 100644 --- a/ww/shiftbuffer.h +++ b/ww/shiftbuffer.h @@ -1,23 +1,23 @@ #pragma once -#include -#include #include -#include // memmove,memcpy +#include +#include #include // free +#include // memmove,memcpy -#if defined(DEBUG) && !defined(hlog) +#if defined(DEBUG) && ! defined(hlog) #include "loggers/network_logger.h" //some logs needs to be printed on debug mode #endif struct shift_buffer_s { - unsigned int lenpos; - unsigned int curpos; - unsigned int cap; // half of full cap - unsigned int full_cap; + unsigned int lenpos; + unsigned int curpos; + unsigned int cap; // half of full cap + unsigned int full_cap; unsigned int *refc; - char *pbuf; + char *pbuf; }; typedef struct shift_buffer_s shift_buffer_t; @@ -26,41 +26,58 @@ void destroyShiftBuffer(shift_buffer_t *self); shift_buffer_t *newShiftBuffer(unsigned int pre_cap); shift_buffer_t *newShadowShiftBuffer(shift_buffer_t *owner); -void reset(shift_buffer_t *self,unsigned int cap); +void reset(shift_buffer_t *self, unsigned int cap); void detachWithSize(shift_buffer_t *self, unsigned int newsize); void expand(shift_buffer_t *self, unsigned int increase); // how many bytes we can fill without realloc -inline unsigned int lCap(shift_buffer_t *self) { return self->curpos; } -inline unsigned int rCap(shift_buffer_t *self) { return (self->full_cap - self->curpos); } +inline unsigned int lCap(shift_buffer_t *self) +{ + return self->curpos; +} +inline unsigned int rCap(shift_buffer_t *self) +{ + return (self->full_cap - self->curpos); +} inline void shiftl(shift_buffer_t *self, unsigned int bytes) { if (lCap(self) < bytes) + { expand(self, (bytes - lCap(self))); + } self->curpos -= bytes; } inline void shiftr(shift_buffer_t *self, unsigned int bytes) { if (rCap(self) < bytes) + { expand(self, (bytes - rCap(self))); + } self->curpos += bytes; } -inline unsigned int bufLen(shift_buffer_t *self) { return self->lenpos - self->curpos; } +inline unsigned int bufLen(shift_buffer_t *self) +{ + return self->lenpos - self->curpos; +} inline void setLen(shift_buffer_t *self, unsigned int bytes) { if (rCap(self) < bytes) + { expand(self, (bytes - rCap(self))); + } self->lenpos = self->curpos + bytes; } inline void reserve(shift_buffer_t *self, unsigned int bytes) { if (rCap(self) < bytes) + { expand(self, (bytes - rCap(self))); + } } inline void consume(shift_buffer_t *self, unsigned int bytes) @@ -68,14 +85,19 @@ inline void consume(shift_buffer_t *self, unsigned int bytes) setLen(self, bufLen(self) - bytes); } -inline const void *rawBuf(shift_buffer_t *self) { return (void *)&(self->pbuf[self->curpos]); } +inline const void *rawBuf(shift_buffer_t *self) +{ + return (void *) &(self->pbuf[self->curpos]); +} inline unsigned char *rawBufMut(shift_buffer_t *self) { #ifdef DEBUG if (*(self->refc) > 1) + { LOGW("writing to a buffer with (refs > 1) is dangerous, do a full copy in this case"); + } #endif - return (void*)&(self->pbuf[self->curpos]); + return (void *) &(self->pbuf[self->curpos]); } inline void writeRaw(shift_buffer_t *restrict self, const void *restrict buffer, unsigned int len) diff --git a/ww/sync_dns.c b/ww/sync_dns.c index 0c5ce3cb..219dfed3 100644 --- a/ww/sync_dns.c +++ b/ww/sync_dns.c @@ -1,6 +1,5 @@ #include "sync_dns.h" #include "loggers/dns_logger.h" -#include "types.h" static inline bool resolve(socket_context_t *dest) { @@ -17,7 +16,7 @@ static inline bool resolve(socket_context_t *dest) LOGE("Connector: resolve failed %s", dest->domain); return false; } - if (logger_will_write_level(LOG_LEVEL_INFO)) + if (logger_will_write_level(getDnsLogger(), (log_level_e)LOG_LEVEL_INFO)) { char ip[60]; sockaddr_str(&(dest->addr), ip, 60); @@ -34,9 +33,9 @@ static inline bool resolve(socket_context_t *dest) return true; } -bool resolveContextSync(socekt_context_t *s_ctx) +bool resolveContextSync(socket_context_t *s_ctx) { // please check these before calling this function -> more performance - assert(s_ctx.atype == SAT_DOMAINNAME && s_ctx.resolved == false && dest->domain != NULL); + assert(s_ctx.atype == kSatDomainName && s_ctx.resolved == false && dest->domain != NULL); return resolve(s_ctx); } \ No newline at end of file diff --git a/ww/tunnel.h b/ww/tunnel.h index 546effc9..47314a5b 100644 --- a/ww/tunnel.h +++ b/ww/tunnel.h @@ -108,10 +108,10 @@ inline void destroyLine(line_t *l) assert(l->chains_state[i] == NULL); } - if (l->dest_ctx.domain != NULL && ! l->dest_ctx.domain_is_constant_memory) - { - assert(l->dest_ctx.domain == NULL); - } + // if (l->dest_ctx.domain != NULL && ! l->dest_ctx.domain_is_constant_memory) + // { + // assert(l->dest_ctx.domain == NULL); + // } #endif // if (l->dest_ctx.domain != NULL && !l->dest_ctx.domain_is_constant_memory) diff --git a/ww/utils/utils.c b/ww/utils/utils.c index 73c0fd37..a8d506a0 100644 --- a/ww/utils/utils.c +++ b/ww/utils/utils.c @@ -201,13 +201,13 @@ void copySocketContextAddr(socket_context_t *dest, socket_context_t **source) switch (dest->atype) { - case SAT_IPV4: + case kSatIpV4: dest->addr.sa.sa_family = AF_INET; dest->addr.sin.sin_addr = (*source)->addr.sin.sin_addr; break; - case SAT_DOMAINNAME: + case kSatDomainName: dest->addr.sa.sa_family = AF_INET; if ((*source)->domain != NULL) { @@ -217,7 +217,7 @@ void copySocketContextAddr(socket_context_t *dest, socket_context_t **source) break; - case SAT_IPV6: + case kSatIpV6: dest->addr.sa.sa_family = AF_INET6; memcpy(&(dest->addr.sin6.sin6_addr), &((*source)->addr.sin6.sin6_addr), sizeof(struct in6_addr)); @@ -228,10 +228,10 @@ void copySocketContextAddr(socket_context_t *dest, socket_context_t **source) enum socket_address_type getHostAddrType(char *host) { if (is_ipv4(host)) - return SAT_IPV4; + return kSatIpV4; if (is_ipv6(host)) - return SAT_IPV6; - return SAT_DOMAINNAME; + return kSatIpV6; + return kSatDomainName; } void copySocketContextPort(socket_context_t *dest, socket_context_t *source) @@ -239,15 +239,15 @@ void copySocketContextPort(socket_context_t *dest, socket_context_t *source) switch (dest->atype) { - case SAT_IPV4: + case kSatIpV4: dest->addr.sin.sin_port = source->addr.sin.sin_port; break; - case SAT_DOMAINNAME: + case kSatDomainName: dest->addr.sin.sin_port = source->addr.sin.sin_port; break; - case SAT_IPV6: + case kSatIpV6: dest->addr.sin6.sin6_port = source->addr.sin6.sin6_port; break; default: @@ -290,7 +290,7 @@ dynamic_value_t parseDynamicStrValueFromJsonObject(const cJSON *json_obj, const { dynamic_value_t result = {0}; - result.status = dvs_empty; + result.status = kDvsEmpty; if (!cJSON_IsObject(json_obj) || json_obj->child == NULL) return result; @@ -301,7 +301,7 @@ dynamic_value_t parseDynamicStrValueFromJsonObject(const cJSON *json_obj, const va_list argp; va_start(argp, matchers); - for (size_t mi = dvs_constant + 1; mi < matchers + dvs_constant + 1; mi++) + for (size_t mi = kDvsConstant + 1; mi < matchers + kDvsConstant + 1; mi++) { char *matcher = va_arg(argp, char *); if (strcmp(matcher, jstr->valuestring) == 0) @@ -313,7 +313,7 @@ dynamic_value_t parseDynamicStrValueFromJsonObject(const cJSON *json_obj, const } va_end(argp); - result.status = dvs_constant; + result.status = kDvsConstant; result.value_ptr = malloc(strlen(jstr->valuestring) + 1); strcpy(result.value_ptr, jstr->valuestring); } @@ -323,7 +323,7 @@ dynamic_value_t parseDynamicNumericValueFromJsonObject(const cJSON *json_obj, co { dynamic_value_t result = {0}; - result.status = dvs_empty; + result.status = kDvsEmpty; if (!cJSON_IsObject(json_obj) || json_obj->child == NULL) return result; @@ -334,7 +334,7 @@ dynamic_value_t parseDynamicNumericValueFromJsonObject(const cJSON *json_obj, co va_list argp; va_start(argp, matchers); - for (size_t mi = dvs_constant + 1; mi < matchers + dvs_constant + 1; mi++) + for (size_t mi = kDvsConstant + 1; mi < matchers + kDvsConstant + 1; mi++) { char *matcher = va_arg(argp, char *); if (strcmp(matcher, jstr->valuestring) == 0) @@ -346,11 +346,11 @@ dynamic_value_t parseDynamicNumericValueFromJsonObject(const cJSON *json_obj, co } va_end(argp); - result.status = dvs_empty; + result.status = kDvsEmpty; } else if (cJSON_IsNumber(jstr)) { - result.status = dvs_constant; + result.status = kDvsConstant; result.value = (size_t)jstr->valueint; } return result;