diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..162984c --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,19 @@ +# Maintainer: Shiwei Zhang + +pkgname=v2socks +pkgdesc="An opinioned lightweight socks5 server and vmess (v2ray) client." +pkgrel=1 +pkgver=0.1.0 +arch=(any) +url='https://github.com/ylxdzsw/v2socks' +license=(GPL3) +makedepends=(cargo) +source=("https://github.com/ylxdzsw/v2socks/archive/v$pkgver.tar.gz") +md5sums=(SKIP) + +package() { + cd "$srcdir/v2socks" + cargo build --release + install -D "$srcdir"/v2socks-$pkgver/target/release/v2socks "$pkgdir"/usr/bin/v2socks + install -Dm644 "$srcdir"/v2socks-$pkgver/v2socks.service "$pkgdir"/usr/lib/systemd/system/v2socks.service +} \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..214519c --- /dev/null +++ b/readme.md @@ -0,0 +1,4 @@ +V2socks +======= + +An opinioned lightweight socks5 server and vmess (v2ray) client. \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 11d5ef6..b12c82d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,7 +71,7 @@ fn vmess(server: &Socks5Server, proxy: String, user_id: [u8; 16]) { let mut stream = stream.try_clone().unwrap(); std::thread::spawn(move || { - let mut reader = VmessReader::::new(conn, key, IV); + let mut reader = VmessReader::new(conn, key, IV); let mut buffer = [0; 1<<14]; loop { let len = reader.read(&mut buffer).unwrap(); diff --git a/src/vmess.rs b/src/vmess.rs index 465f4d4..a893e06 100644 --- a/src/vmess.rs +++ b/src/vmess.rs @@ -39,23 +39,6 @@ impl VmessReader> { } } -impl VmessReader { - /// key and IV are just data key and iv in the request header, this function will calculate the md5 it selfs - #[allow(non_snake_case)] - pub fn new(conn: std::net::TcpStream, key: [u8; 16], IV: [u8; 16]) -> Self { - let mut reader = VmessReader { - reader: conn, - decoder: AES128CFB::new(md5!(&key), md5!(&IV)) - }; - reader.handshake(); - reader - } - - pub fn into_inner(self) -> std::net::TcpStream { - self.reader - } -} - impl VmessReader { fn handshake(&mut self) { let mut head = [0; 4]; @@ -211,7 +194,7 @@ impl Write for VmessWriter { } } -fn fnv1a(x: &[u8]) -> u32 { // checked +fn fnv1a(x: &[u8]) -> u32 { let prime = 16777619; let mut hash = 0x811c9dc5; for byte in x.iter() { diff --git a/v2socks.service b/v2socks.service new file mode 100644 index 0000000..f483ab9 --- /dev/null +++ b/v2socks.service @@ -0,0 +1,6 @@ +[Unit] +Description=v2socks + +[Service] +Type=simple +ExecStart=/usr/bin/v2socks plain \ No newline at end of file