Understanding Shadowsocks

Introduction

TCP/IP & Tun/Tap Devices

// Print out the packet, mini Wireshark.
static void pkgdbg(buffer_t *buf) {
int i = 0;
int len = buf->len;
for (i = 0; i < len; i++) {
if ((i % 16) == 0)
ferr("%08x: ", i);
if (isprint(buf->data[i])) {
ferr("%c", buf->data[i]);
}
else {
ferr(".");
}
if ((i % 16) == 15) {
ferr("\n");
}
}
if ((i % 16) != 0) ferr("\n");
// ferr("packet buffer(raw):\n");
// for (i = 0; i < len; i++) {
// if ((i % 16) == 0)
// ferr("%08x: ", i);
// if ((i % 2) == 0)
// ferr(" ");
// ferr("%02x", buf->data[i]);
// if ((i % 16) == 15)
// ferr("\n");
// }
// if ((i % 16) != 0)
// ferr("\n");
}
else
ferr(".");
if ((i % 16) == 15)
ferr("\n");
}
if ((i % 16) != 0) ferr("\n");
// ferr("packet buffer(raw):\n");
// for (i = 0; i < len; i++) {
// if ((i % 16) == 0)
// ferr("%08x: ", i);
// if ((i % 2) == 0)
// ferr(" ");
// ferr("%02x", buf->data[i]);
// if ((i % 16) == 15)
// ferr("\n");
// }
// if ((i % 16) != 0)
// ferr("\n");
}
$ cloc ./
80 text files.
78 unique files.
7 files ignored.

github.com/AlDanial/cloc v 1.82 T=0.05 s (1488.4 files/s, 163686.6 lines/s)
--------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------
C 37 525 749 4913
C/C++ Header 22 229 82 1234
make 10 45 4 184
Bourne Shell 2 9 32 49
Markdown 1 8 0 44
JSON 2 0 0 31
--------------------------------------------------------------------
SUM: 74 816 867 6455
--------------------------------------------------------------------

SOCKS5

  1. TCP/IP handshake.
  2. SOCKS5 handshake
  • client: I’d like to use SOCKS version, Auth method.
  • server: here is my choice, SOCKS version and Auth method.
  • client: I want to connect to this domain at this port.
  • server: look good to me.
  • client -> server: full HTTP request (there is no extra header in this frame for SOCKS5 info after handshake is done).
SOCKS Protocol
  • server -> client: full HTTP response.

lib-ev

ev_io_init(&server->recv_ctx->io, server_recv_cb, fd, EV_READ);
static void remote_recv_cb(EV_P_ ev_io *w, int revents) {
remote_ctx_t *remote_recv_ctx = (remote_ctx_t *)w;
remote_t *remote = remote_recv_ctx->remote;
...
}
struct my_io {
ev_io io;
int otherfd;
void *somedata;
struct whatever *mostinteresting;
};

struct my_io w;
ev_io_init (&w.io, my_cb, fd, EV_READ);
static void my_cb (struct ev_loop *loop, ev_io *w_, int revents){ 
struct my_io *w = (struct my_io *)w_;

}

Shadowsocks White Paper

Conclusion

--

--

--

hacker, lifetime learner

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Team Insights: Mario, Full Stack Engineer and Scrum Master

Fun with HTML Canvas: Let’s make Lava Lamp Plasma

Cardano Fans Development Update — 14.11.2021

Updating Non-Primitive Columns Types Using Sqlalchemy and Postgres

What are the most effective and efficient ways for beginners to learn DSA?

Speed up your Bash, Python and Julia Command Line Editing

Please stop using loop in python !!

Integrating LVM Partitioning with Hadoop and automating via ANSIBLE

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
oliver hu

oliver hu

hacker, lifetime learner

More from Medium

“When there’s a delusion, a mass delusion, you can say everybody is to blame.

Culling: The Sad Reality of The IMF and World Bank Loans As Triggers of Wars.

‘The Father and I are one’ Verse

Legend: The Order of the Phoenix Location