1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-19 17:53:28 +00:00

Updated DNS Cache logic

This commit is contained in:
Bryan Roe
2020-02-24 16:00:08 -08:00
parent f11fb9d3cb
commit 7f49bedd29

View File

@@ -452,18 +452,19 @@ duk_ret_t ILibDuktape_net_socket_connect(duk_context *ctx)
if (dest.sin6_family == AF_UNSPEC || (duk_is_object(ctx, 0) && duk_has_prop_string(ctx, 0, "proxy") && proxy.sin6_family == AF_UNSPEC)) if (dest.sin6_family == AF_UNSPEC || (duk_is_object(ctx, 0) && duk_has_prop_string(ctx, 0, "proxy") && proxy.sin6_family == AF_UNSPEC))
{ {
// Can't resolve, check to see if it's cached // Can't resolve, check to see if it's cached
duk_push_heap_stash(ctx); duk_push_heap_stash(ctx); // [stash]
if (duk_has_prop_string(ctx, -1, "_sharedDB")) if (duk_has_prop_string(ctx, -1, "_sharedDB"))
{ {
ILibSimpleDataStore db = (ILibSimpleDataStore)Duktape_GetPointerProperty(ctx, -1, "_sharedDB"); ILibSimpleDataStore db = (ILibSimpleDataStore)Duktape_GetPointerProperty(ctx, -1, "_sharedDB");
char *dnsCache = (char*)duk_push_sprintf(ctx, "DNS[%s]", host); // [dnsCache] char *dnsCache = (char*)duk_push_sprintf(ctx, "DNS[%s]", host); // [stash][dnsCache]
char dnsCacheBuffer[255]; char dnsCacheBuffer[255];
if (ILibSimpleDataStore_Get(db, dnsCache, dnsCacheBuffer, sizeof(dnsCacheBuffer)) > 0) if (ILibSimpleDataStore_Get(db, dnsCache, dnsCacheBuffer, sizeof(dnsCacheBuffer)) > 0)
{ {
ILibResolveEx(dnsCacheBuffer, (unsigned short)port, &dest); ILibResolveEx(dnsCacheBuffer, (unsigned short)port, &dest);
} }
duk_pop(ctx); // ... duk_pop(ctx); // [stash]
} }
duk_pop(ctx); // ...
} }
if (dest.sin6_family == AF_UNSPEC || (duk_is_object(ctx, 0) && duk_has_prop_string(ctx, 0, "proxy") && proxy.sin6_family == AF_UNSPEC)) if (dest.sin6_family == AF_UNSPEC || (duk_is_object(ctx, 0) && duk_has_prop_string(ctx, 0, "proxy") && proxy.sin6_family == AF_UNSPEC))
{ {
@@ -1985,17 +1986,19 @@ duk_ret_t ILibDuktape_TLS_connect(duk_context *ctx)
if (dest.sin6_family == AF_UNSPEC || (duk_has_prop_string(ctx, 0, "proxy") && proxy.sin6_family == AF_UNSPEC)) if (dest.sin6_family == AF_UNSPEC || (duk_has_prop_string(ctx, 0, "proxy") && proxy.sin6_family == AF_UNSPEC))
{ {
// Can't resolve, check to see if it's cached // Can't resolve, check to see if it's cached
duk_push_heap_stash(ctx); duk_push_heap_stash(ctx); // [stash]
if (duk_has_prop_string(ctx, -1, "_sharedDB")) if (duk_has_prop_string(ctx, -1, "_sharedDB"))
{ {
ILibSimpleDataStore db = (ILibSimpleDataStore)Duktape_GetPointerProperty(ctx, -1, "_sharedDB"); ILibSimpleDataStore db = (ILibSimpleDataStore)Duktape_GetPointerProperty(ctx, -1, "_sharedDB");
char *dnsCache = (char*)duk_push_sprintf(ctx, "DNS[%s]", host); char *dnsCache = (char*)duk_push_sprintf(ctx, "DNS[%s]", host); // [stash][dnsCache]
char dnsCacheBuffer[255]; char dnsCacheBuffer[255];
if (ILibSimpleDataStore_Get(db, dnsCache, dnsCacheBuffer, sizeof(dnsCacheBuffer)) > 0) if (ILibSimpleDataStore_Get(db, dnsCache, dnsCacheBuffer, sizeof(dnsCacheBuffer)) > 0)
{ {
ILibResolveEx(dnsCacheBuffer, (unsigned short)port, &dest); ILibResolveEx(dnsCacheBuffer, (unsigned short)port, &dest);
} }
duk_pop(ctx); // [stash]
} }
duk_pop(ctx); // ...
} }
if (dest.sin6_family == AF_UNSPEC || (duk_has_prop_string(ctx, 0, "proxy") && proxy.sin6_family == AF_UNSPEC)) if (dest.sin6_family == AF_UNSPEC || (duk_has_prop_string(ctx, 0, "proxy") && proxy.sin6_family == AF_UNSPEC))
{ {