Rename to shadowsocks-c with libuv, async DNS and CI lint (#3051)

Rename the project to shadowsocks-c while retaining ss-* commands, the embedding ABI, and legacy library/package lookup compatibility.

Replace libev with bundled libuv for IOCP/kqueue event backends, expand asynchronous runtime DNS coverage, and add actionlint/Ruff with strict clang-tidy failure handling. Validate native platforms, static builds, packaging, interoperability, sanitizers, and canonical/legacy consumers.

All 22 hosted checks pass at reviewed head a8493250eb.
This commit is contained in:
Max Lv
2026-09-11 14:18:37 +08:00
committed by GitHub
parent 201e70c4bd
commit bdc77408cb
61 changed files with 1695 additions and 851 deletions
+7
View File
@@ -199,3 +199,10 @@ endif()
ss_add_test(test_acl_literal
"test_acl_literal.c;${PROJECT_SOURCE_DIR}/src/acl.c;${PROJECT_SOURCE_DIR}/src/ipset.c;${PROJECT_SOURCE_DIR}/src/rule.c;${PROJECT_SOURCE_DIR}/src/utils.c"
"${TEST_LITERAL_LIBS}")
ss_add_test(test_event "test_event.c" "ss_ev")
set_tests_properties(test_event PROPERTIES TIMEOUT 30)
ss_add_test(test_resolv_async
"test_resolv_async.c;${PROJECT_SOURCE_DIR}/src/resolv.c;${PROJECT_SOURCE_DIR}/src/utils.c"
"ss_ev;ss_cares;ss_sodium")
set_tests_properties(test_resolv_async PROPERTIES TIMEOUT 30)
+43
View File
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
"""Exercise client hostname ACL bypass with an unreachable proxy upstream."""
import argparse
import concurrent.futures
import os
from pathlib import Path
import tempfile
import threading
from interop import TCPOrigin, TCPHandler, free_port, peers, tcp_case
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--bin', required=True, type=Path)
parser.add_argument('--isolate-windows-runtime', action='store_true')
args = parser.parse_args()
environment = None
if args.isolate_windows_runtime:
environment = os.environ.copy()
root = os.environ['SYSTEMROOT']
environment['PATH'] = root + '\\System32;' + root
local = args.bin.resolve() / ('ss-local.exe' if os.name == 'nt' else 'ss-local')
with tempfile.TemporaryDirectory() as temp, TCPOrigin(('127.0.0.1', 0), TCPHandler) as origin:
threading.Thread(target=origin.serve_forever, daemon=True).start()
try:
for policy in ('[bypass_all]\n', '[proxy_all]\n[bypass_list]\nfull:localhost\n'):
acl = Path(temp) / 'acl'
acl.write_text(policy)
port, upstream = free_port(), free_port()
command = [str(local), '-s', '127.0.0.1', '-p', str(upstream), '-l', str(port),
'-k', 'dns-integration', '-m', 'aes-128-gcm', '--acl', str(acl)]
with peers([command], [port], environment):
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as pool:
futures = [pool.submit(tcp_case, port, origin.server_address[1], size)
for size in (1, 65536, 1048576)]
for future in futures: future.result(timeout=15)
print('PASS hostname ACL bypass: ' + policy.splitlines()[0], flush=True)
finally:
origin.shutdown()
if __name__ == '__main__':
main()
+1 -1
View File
@@ -8,7 +8,7 @@ from pathlib import Path
WINDOWS_SYSTEM_DLLS = {
'advapi32.dll', 'bcrypt.dll', 'crypt32.dll', 'dnsapi.dll', 'iphlpapi.dll',
'kernel32.dll', 'msvcrt.dll', 'ntdll.dll', 'ole32.dll', 'psapi.dll',
'dbghelp.dll', 'kernel32.dll', 'msvcrt.dll', 'ntdll.dll', 'ole32.dll', 'psapi.dll',
'rpcrt4.dll', 'secur32.dll', 'shell32.dll', 'ucrtbase.dll', 'user32.dll',
'userenv.dll', 'winmm.dll', 'ws2_32.dll',
}
+14 -1
View File
@@ -1,8 +1,21 @@
cmake_minimum_required(VERSION 3.20)
project(shadowsocks_consumer LANGUAGES C)
find_package(shadowsocks-libev CONFIG REQUIRED)
set(SS_PACKAGE_NAME shadowsocks-c CACHE STRING "Installed package to test")
find_package(${SS_PACKAGE_NAME} CONFIG REQUIRED)
foreach(kind shared static)
if(TARGET shadowsocks::${kind})
if(SS_PACKAGE_NAME STREQUAL "shadowsocks-libev")
# Exercise legacy filenames as well as legacy package discovery.
foreach(property IMPORTED_LOCATION IMPORTED_IMPLIB)
get_target_property(location shadowsocks::${kind} ${property})
if(location)
get_filename_component(directory "${location}" DIRECTORY)
get_filename_component(filename "${location}" NAME)
string(REPLACE "shadowsocks-c" "shadowsocks-libev" filename "${filename}")
set_property(TARGET shadowsocks::${kind} PROPERTY ${property} "${directory}/${filename}")
endif()
endforeach()
endif()
add_executable(consumer_${kind} main.c)
target_link_libraries(consumer_${kind} PRIVATE shadowsocks::${kind})
endif()
+3 -3
View File
@@ -172,10 +172,10 @@ done
# Shared library should be findable by ldconfig
sudo ldconfig
if ldconfig -p | grep -q libshadowsocks-libev; then
check_pass "libshadowsocks-libev found by ldconfig"
if ldconfig -p | grep -q libshadowsocks-c; then
check_pass "libshadowsocks-c found by ldconfig"
else
check_fail "libshadowsocks-libev not found by ldconfig"
check_fail "libshadowsocks-c not found by ldconfig"
fi
# Header should be in the include path
+84
View File
@@ -0,0 +1,84 @@
#include "test_helpers.h"
#include <string.h>
#include "ss_event.h"
#include <uv.h>
#ifdef __APPLE__
#include <sys/event.h>
#endif
int verbose = 0;
struct receiver { ss_io io; int count; };
static void receive(struct ss_loop *loop, ss_io *io, int events)
{
struct receiver *r = (struct receiver *)io;
char byte;
assert(events & SS_READ);
assert(recv(io->fd, &byte, 1, 0) == 1 && byte == 'x');
r->count++;
ss_io_stop(loop, io);
}
struct shared { ss_io io; ss_io *other; int *calls; };
static void destroy_peer(struct ss_loop *loop, ss_io *io, int events)
{
(void)events;
struct shared *s = (struct shared *)io;
(*s->calls)++;
ss_io_stop(loop, s->other);
free(s->other);
ss_io_stop(loop, io);
free(s);
}
static void must_not_run(struct ss_loop *loop, ss_io *io, int events)
{
(void)loop; (void)io; (void)events;
assert(!"stopped watcher was invoked");
}
int main(void)
{
test_network_init();
struct ss_loop *loop = ss_loop_new(0);
assert(loop);
#ifdef _WIN32
assert(strcmp(ss_backend_name(), "iocp") == 0);
assert(ss_native_loop(loop)->iocp != NULL);
#elif defined(__APPLE__)
assert(strcmp(ss_backend_name(), "kqueue") == 0);
struct timespec zero = {0};
assert(kevent(uv_backend_fd(ss_native_loop(loop)), NULL, 0, NULL, 0, &zero) == 0);
#endif
/* Exceed Winsock select's default 64 descriptors. */
struct receiver receivers[256] = {0};
ss_socket_t sender = socket(AF_INET, SOCK_DGRAM, 0);
for (unsigned i = 0; i < 256; i++) {
int fd = (int)socket(AF_INET, SOCK_DGRAM, 0);
struct sockaddr_in address = {0};
address.sin_family = AF_INET;
address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
assert(bind(fd, (struct sockaddr *)&address, sizeof(address)) == 0);
socklen_t length = sizeof(address);
assert(getsockname(fd, (struct sockaddr *)&address, &length) == 0);
ss_io_init(&receivers[i].io, receive, fd, SS_READ);
ss_io_start(loop, &receivers[i].io);
assert(sendto(sender, "x", 1, 0, (struct sockaddr *)&address, length) == 1);
}
ss_run(loop, 0);
for (unsigned i = 0; i < 256; i++) {
assert(receivers[i].count == 1);
ss_socket_close(receivers[i].io.fd);
}
/* Both directions share one poll handle; freeing a pending peer is safe. */
int calls = 0;
ss_io *other = calloc(1, sizeof(*other));
struct shared *owner = calloc(1, sizeof(*owner));
assert(other && owner);
ss_io_init(other, must_not_run, (int)sender, SS_WRITE);
ss_io_init(&owner->io, destroy_peer, (int)sender, SS_WRITE);
owner->other = other; owner->calls = &calls;
ss_io_start(loop, other);
ss_io_start(loop, &owner->io);
ss_run(loop, 0);
assert(calls == 1);
ss_socket_close(sender);
assert(ss_run(loop, SS_RUN_NOWAIT) == 0);
ss_loop_destroy(loop);
return 0;
}
+1
View File
@@ -113,6 +113,7 @@ test_get_sockaddr_rejects_invalid_ip_literal_ports(void)
struct sockaddr_in *addr4 = (struct sockaddr_in *)&storage;
memset(&storage, 0, sizeof(storage));
assert(get_sockaddr("localhost", "8388", &storage, 0, 0) == -1);
assert(get_sockaddr("127.0.0.1", "8388", &storage, 0, 0) == 0);
assert(addr4->sin_family == AF_INET);
assert(ntohs(addr4->sin_port) == 8388);
+5 -5
View File
@@ -1,6 +1,6 @@
/* Exercise real c-ares cancellation with outstanding A and AAAA requests. */
#include "test_helpers.h"
#include <ev.h>
#include "ss_event.h"
#include "resolv.h"
int verbose = 0;
@@ -32,7 +32,7 @@ int main(void)
assert(getsockname(sink, (struct sockaddr *)&address, &size) == 0);
char nameserver[64];
snprintf(nameserver, sizeof(nameserver), "127.0.0.1:%u", ntohs(address.sin_port));
struct ev_loop *loop = ev_loop_new(0);
struct ss_loop *loop = ss_loop_new(0);
assert(loop != NULL);
for (unsigned round = 0; round < 3; round++) {
struct result results[64] = {{0}};
@@ -42,15 +42,15 @@ int main(void)
snprintf(hostname, sizeof(hostname), "pending-%u.invalid", i);
resolv_start(hostname, htons(443), resolved, released, &results[i]);
}
ev_run(loop, EVRUN_NOWAIT);
ss_run(loop, SS_RUN_NOWAIT);
resolv_shutdown(loop);
for (unsigned i = 0; i < 64; i++) {
assert(results[i].called == 1);
assert(results[i].freed == 1);
}
assert(ev_run(loop, EVRUN_NOWAIT) == 0);
assert(ss_run(loop, SS_RUN_NOWAIT) == 0);
}
ev_loop_destroy(loop);
ss_loop_destroy(loop);
ss_socket_close(sink);
return 0;
}
+140
View File
@@ -0,0 +1,140 @@
/* Local delayed DNS server proves A/AAAA/NXDOMAIN completion without blocking. */
#include "test_helpers.h"
#include <string.h>
#include "ss_event.h"
#include "resolv.h"
int verbose = 0;
struct packet {
struct packet *next;
struct sockaddr_storage peer;
socklen_t peer_len;
unsigned char bytes[512];
size_t length;
};
static struct packet *packets;
static ss_io dns_io;
static ss_timer reply_timer, ticker, deadline;
static unsigned ticks, completed;
static int family;
struct result { unsigned called, freed; int missing; };
static void reply(struct ss_loop *loop, ss_timer *timer, int events)
{
(void)loop; (void)timer; (void)events;
while (packets) {
struct packet *p = packets;
packets = p->next;
assert(sendto(dns_io.fd, (const char *)p->bytes, (int)p->length, 0,
(struct sockaddr *)&p->peer, p->peer_len) == (int)p->length);
free(p);
}
}
static void question(struct ss_loop *loop, ss_io *io, int events)
{
(void)events;
struct packet *p = calloc(1, sizeof(*p));
assert(p);
p->peer_len = sizeof(p->peer);
int count = (int)recvfrom(io->fd, (char *)p->bytes, sizeof(p->bytes), 0,
(struct sockaddr *)&p->peer, &p->peer_len);
assert(count > 16 && p->bytes[4] == 0 && p->bytes[5] == 1);
size_t end = 12;
while (end < (size_t)count && p->bytes[end]) end += p->bytes[end] + 1;
end += 5; /* terminating zero, QTYPE, QCLASS */
assert(end <= (size_t)count && end + 28 <= sizeof(p->bytes));
unsigned type = p->bytes[end - 3];
int missing = p->bytes[13] == 'm';
p->bytes[2] = 0x81; p->bytes[3] = missing ? 0x83 : 0x80;
p->bytes[6] = 0; p->bytes[7] = missing ? 0 : 1;
memset(p->bytes + 8, 0, 4);
p->length = end;
if (!missing) {
unsigned char answer[] = {0xc0,0x0c,0,0,0,1,0,0,0,1,0,0};
assert(type == 1 || type == 28);
answer[3] = (unsigned char)type;
answer[11] = type == 1 ? 4 : 16;
memcpy(p->bytes + end, answer, sizeof(answer));
p->length += sizeof(answer);
memset(p->bytes + p->length, 0, 16);
if (type == 1) { p->bytes[p->length] = 127; p->bytes[p->length+3] = 1; }
else p->bytes[p->length+15] = 1;
p->length += answer[11];
}
p->next = packets; packets = p;
ss_timer_start(loop, &reply_timer);
}
static void tick(struct ss_loop *loop, ss_timer *timer, int events)
{
(void)loop; (void)timer; (void)events; ticks++;
}
static void timed_out(struct ss_loop *loop, ss_timer *timer, int events)
{
(void)loop; (void)timer; (void)events;
assert(!"asynchronous DNS did not complete");
}
static struct ss_loop *test_loop;
static void resolved(struct sockaddr *address, void *data)
{
struct result *r = data;
assert(!r->called && !r->freed && ticks > 2);
r->called++;
if (r->missing) assert(address == NULL);
else {
assert(address && address->sa_family == family);
if (family == AF_INET) assert(((struct sockaddr_in *)address)->sin_port == htons(443));
else assert(((struct sockaddr_in6 *)address)->sin6_port == htons(443));
}
if (++completed == 33) ss_unloop(test_loop, SS_UNLOOP_ALL);
}
static void released(void *data)
{
struct result *r = data;
assert(r->called == 1 && !r->freed);
r->freed++;
}
int main(void)
{
test_network_init();
test_loop = ss_loop_new(0);
int fd = (int)socket(AF_INET, SOCK_DGRAM, 0);
struct sockaddr_in address = {0};
address.sin_family = AF_INET;
address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
assert(bind(fd, (struct sockaddr *)&address, sizeof(address)) == 0);
socklen_t length = sizeof(address);
assert(getsockname(fd, (struct sockaddr *)&address, &length) == 0);
char nameserver[64];
snprintf(nameserver, sizeof(nameserver), "127.0.0.1:%u", ntohs(address.sin_port));
ss_io_init(&dns_io, question, fd, SS_READ);
ss_timer_init(&reply_timer, reply, .05, 0);
ss_timer_init(&ticker, tick, .001, .001);
ss_timer_init(&deadline, timed_out, 10, 0);
for (int ipv6 = 0; ipv6 < 2; ipv6++) {
struct result results[33] = {{0}};
results[32].missing = 1;
family = ipv6 ? AF_INET6 : AF_INET;
ticks = completed = 0;
assert(resolv_init(test_loop, nameserver, ipv6) == 0);
ss_io_start(test_loop, &dns_io);
ss_timer_start(test_loop, &ticker);
ss_timer_start(test_loop, &deadline);
for (unsigned i = 0; i < 33; i++) {
char host[64];
snprintf(host, sizeof(host), "%s-%u.invalid", i == 32 ? "missing" : "resolved", i);
resolv_start(host, htons(443), resolved, released, &results[i]);
}
assert(completed == 0);
ss_run(test_loop, 0);
assert(completed == 33);
for (unsigned i = 0; i < 33; i++) assert(results[i].called == 1 && results[i].freed == 1);
resolv_shutdown(test_loop);
ss_io_stop(test_loop, &dns_io);
ss_timer_stop(test_loop, &ticker);
ss_timer_stop(test_loop, &deadline);
ss_timer_stop(test_loop, &reply_timer);
assert(!packets);
assert(ss_run(test_loop, SS_RUN_NOWAIT) == 0);
}
ss_socket_close(fd);
ss_loop_destroy(test_loop);
return 0;
}