GithubHelp home page GithubHelp logo

wkgcass / vproxy Goto Github PK

View Code? Open in Web Editor NEW
138.0 14.0 35.0 8.28 MB

1) proxy: LB,DNS,Socks. 2) k8s: CRD and Controllers. 3) sdn: TCP/IP Stack + Flow Tables.

License: MIT License

Java 67.05% JavaScript 0.07% Dockerfile 0.02% Thrift 0.01% Shell 1.08% C 26.61% Makefile 0.24% Python 0.21% HTML 0.01% Batchfile 0.01% Kotlin 4.73%
loadbalancer kubernetes panama sdn

vproxy's Introduction

vproxy

Build Status

中文文档

Intro

VProxy is a zero-dependency loadbalancer and sdn virtual switch. The project only requires Java 21 to run.

Clone it, compile it, then everything is ready for running.

Features

  1. TCP Loadbalancer with TLS termination
  2. HTTP/1.x and HTTP/2 Loadbalancer with Host header consideration
  3. Other tcp based protocol loadbalancer, such as grpc, dubbo
  4. Socks5 server
  5. DNS server and customizable A|AAAA records
  6. Kubernetes integration
  7. Many other standalone extended apps, such as WebSocksProxyAgent and WebSocksProxyServer
  8. SDN virtual switch with full TCP/IP stack support

Make

use pre-built releases

See the release page.

For linux

Use the latest vproxy-linux binary file in release page.

Or

Use the jlink built runtime here.

For macos

Use the latest vproxy-macos binary file in release page.

For windows

Java runtime can be found here.

For musl

Use the jlink built runtime here.

build prerequisites

Run:

make init

to initiate submodules and some other init work.

jar package
./gradlew clean jar
java -jar build/libs/vproxy.jar -Deploy=HelloWorld
jlink
make jlink
./build/image/bin/vproxy -Deploy=HelloWorld
docker
# make docker
docker run -it --rm vproxyio/vproxy -Deploy=HelloWorld
graal native-image
make image
./vproxy -Deploy=HelloWorld
native fds impl

Only macos(bsd)/linux supported.

make vfdposix
java -Dvfd=posix -Djava.library.path=./base/src/main/c -jar build/libs/vproxy.jar -Deploy=HelloWorld

And there's a special version for windows to support Tap devices: -Dvfd=windows, however the normal fds and event loop are still based on jdk selector channel.

make vfdwindows
java -Dvfd=windows -Djava.library.path=./base/src/main/c -jar build/libs/vproxy.jar -Deploy=HelloWorld

Windows TAP depends on OpenVPN TAP Driver. MacOS TAP depends on tuntaposx.

MacOS TUN, Linux TAP and TUN has no extra dependencies.

xdp

It's recommended to run a kernel with minimum version 5.10 (or at least 5.4) in order to use xdp support in the switch module.
If using a lower version, you cannot share the same umem with different xdp interfaces.

To build the xdp support, you will need these packages: apt-get install -y linux-headers-$(uname -r) build-essential libelf-dev clang llvm, then:

make vpxdp

Or compile it inside a docker container on a non-Linux platform:

make vpxdp-linux
test

Run test cases:

./gradlew runTest

Run test cases in docker:

make dockertest

Test vswitch, docker network plugin, vpctl, k8s controller:

# requires virtualbox installed

cd ./misc/auto-setup/
./auto-setup.sh
./auto-verify.sh
ui

vproxy provides some ui tools.

./gradlew ui:jar
java -cp ./ui/build/libs/vproxy-ui.jar $mainClassName

Current available ui tools:

  1. io.vproxy.ui.calculator.CalculatorMain: an IPv4 network calculator

Aim

  • Zero dependency: all dependencies are implemented in vproxy subprojects.
  • Simple: keep code simple and clear.
  • Modifiable when running: no need to reload for configuration update.
  • Fast: performance is one of our main priorities.
  • TCP Loadbalancer: we now support TCP and TCP based protocols, also allow your own protocols.
  • Kubernetes: integrate vproxy resources into k8s.
  • SDN: modifying and forwarding packets with flows and routes.

How to use

use as a library

gradle

implementation group: 'io.vproxy', name: 'vproxy-adaptor-netty', version: '1.0.0-BETA-12'
// all available artifacts: dep, base, adaptor-netty, adaptor-vertx

maven

<dependency>
    <groupId>io.vproxy</groupId>
    <artifactId>vproxy-adaptor-netty</artifactId>
    <version>1.0.0-BETA-12</version>
</dependency>
<!-- all available artifacts: dep, base, adaptor-netty, adaptor-vertx -->

module-info.java

requires io.vproxy.dep;
requires io.vproxy.base;
requires io.vproxy.adaptor.netty;
requires io.vproxy.adaptor.vertx;

netty

var acceptelg = new VProxyEventLoopGroup();
var elg = new VProxyEventLoopGroup(4);
var bootstrap = new ServerBootstrap();
bootstrap
    .channel(VProxyInetServerSocketChannel.class)
    .childHandler(new ChannelInitializer<>() {
        @Override
        protected void initChannel(Channel ch) {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new HttpServerCodec());
            p.addLast(new HttpHelloWorldServerHandler());
        }
    });
bootstrap.group(acceptelg, elg);
bootstrap.bind(hostname, port).sync();
use vproxy with kubernetes

Add crd, launch vproxy and controller

kubectl apply -f https://github.com/vproxy-tools/vpctl/blob/master/misc/crd.yaml
kubectl apply -f https://github.com/vproxy-tools/vpctl/blob/master/misc/k8s-vproxy.yaml

Launch the example app

kubectl apply -f https://github.com/vproxy-tools/vpctl/blob/master/misc/cr-example.yaml

Detailed info can be found here.

vpctl

A command line client application is provided to manipulate the vproxy instance. You may see more info in vpctl repo.

This tool is fully tested and simple to use. Some examples are provided in the tool repo for reference.

Simple mode

You can start a simple loadbalancer in one command:

java -Deploy=Simple -jar vproxy.jar \  
                bind {port} \
                backend {host1:port1,host2:port2} \
                [ssl {path of cert1,cert2} {path of key}] \
                [protocol {...}] \

Use help to view the parameters.

Standard mode

Use help to view the launching parameters.

After launching, you may use help, man, man ${action}, man ${resource}, man ${resource} ${action} to check the command manual. Also you can use System: help to check the system commands.

After launching vproxy, you may use System: to run some system commands, You may create http-controllers and resp-controllers. Then you can operate the vproxy instance using curl or redis-cli. You may also operate the vproxy instance directly using standard input (stdin).

See command.md and api doc for more info.

Doc

Products

Contribute

Currently only I myself is working on this project. I would be very happy if you want to join :)

Thanks to those who had committed PR, see CONTRIB.

vproxy's People

Contributors

gcnyin avatar nintha avatar wkgcass avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vproxy's Issues

Time wheel implementation required

目前的定时任务是通过PriorityQueue维护的,考虑换成时间轮。

由于常见的TCP超时时间是15分钟(例如LVS),而UDP则更短,一般认为不会出现超过15分钟的定时任务

使用4层时间轮,每层32个元素。可以表示32^4=1048576 ms > 15 minutes。使用链表维护同一毫秒的定时任务列表。使用32是因为%操作可以优化为&操作

不需要考虑并发,时间事件的访问总是在eventloop里面进行的。

对于超过1048576ms的定时任务,放在PriorityQueue中排序,当时间低于1048576 ms时从队列中挪出来放进时间轮里。

需要实现的接口:TimeQueue.javaTimeEvent.java

why i cross the gfw unsuccessfully?

hi.

yudeMacBook-Air:~ brite$ java -Deploy=WebSocksProxyAgent -jar vproxy.jar websocks-agent-example.conf
[12:52:46.997]main - net.cassite.vproxy.component.svrgroup.ServerGroup$ServerHandle#restart(219) - health check for 127.0.0.1(/127.0.0.1:18686) is started on loop worker-loop-0
[12:52:47.78]main - net.cassite.vproxy.component.svrgroup.ServerGroup$ServerHandle#restart(219) - health check for 127.0.0.1(/127.0.0.1:18687) is started on loop worker-loop-1
[12:52:47.602]ALERT - pac server started on 0
[12:52:47.611]ALERT - agent started on 11080

[12:55:14.75]ALERT - proxy the request to www.google.com:443 via DEFAULT
[12:55:14.89]ALERT - proxy the request to www.blogger.com:443 via DEFAULT
[12:55:14.90]ALERT - proxy the request to apis.google.com:443 via DEFAULT
[12:55:14.108]ALERT - proxy the request to www.gstatic.com:443 via DEFAULT
[12:55:14.367]ALERT - proxy the request to apis.google.com:443 via DEFAULT
[12:55:14.369]ALERT - proxy the request to www.gstatic.com:443 via DEFAULT
[12:55:14.369]ALERT - proxy the request to www.blogger.com:443 via DEFAULT
[12:55:15.760]ALERT - proxy the request to www.gstatic.com:443 via DEFAULT
[12:55:15.761]ALERT - proxy the request to www.blogger.com:443 via DEFAULT
[12:55:15.762]ALERT - proxy the request to apis.google.com:443 via DEFAULT
[12:55:20.826]ALERT - proxy the request to apis.google.com:443 via DEFAULT
[12:55:20.836]ALERT - proxy the request to www.gstatic.com:443 via DEFAULT
[12:55:32.189]ALERT - proxy the request to www.google.com:443 via DEFAULT
[12:55:32.315]ALERT - proxy the request to www.google.com:443 via DEFAULT
[12:55:32.386]ALERT - proxy the request to www.google.com:443 via DEFAULT
[12:55:33.175]ALERT - proxy the request to www.google.com:443 via DEFAULT
[12:55:33.613]ALERT - proxy the request to www.google.com:443 via DEFAULT
[12:55:33.629]ALERT - proxy the request to geoiplookup.net:80 via DEFAULT
[12:55:33.629]ALERT - proxy the request to geoiplookup.net:80 via DEFAULT
[12:55:33.678]ALERT - proxy the request to geoiplookup.net:80 via DEFAULT
[12:55:34.92]ALERT - proxy the request to www.google.com:443 via DEFAULT
[12:55:34.110]ALERT - proxy the request to geoiplookup.net:80 via DEFAULT
[12:55:34.111]ALERT - proxy the request to geoiplookup.net:80 via DEFAULT
[12:55:34.508]ALERT - proxy the request to geoiplookup.net:80 via DEFAULT
[12:55:34.509]ALERT - proxy the request to geoiplookup.net:80 via DEFAULT
[12:55:34.588]ALERT - proxy the request to geoiplookup.net:80 via DEFAULT
[12:55:35.661]ALERT - proxy the request to geoiplookup.net:80 via DEFAULT
[12:55:35.661]ALERT - proxy the request to geoiplookup.net:80 via DEFAULT
[12:55:35.680]ALERT - proxy the request to geoiplookup.net:80 via DEFAULT
[12:55:40.709]ALERT - proxy the request to geoiplookup.net:80 via DEFAULT
[12:55:40.710]ALERT - proxy the request to geoiplookup.net:80 via DEFAULT
[12:55:40.728]ALERT - proxy the request to geoiplookup.net:80 via DEFAULT
^CyudeMacBook-Air:~ brite$

谢谢回复。

有个问题,总该连接代理服务器,才能翻墙。但是在哪里设置代理服务器的公网ip及其端口 ?
我都没看到设置的地方

java新手不知道如何编译

是需要cd到源代码目录下执行javac进行编译么,预设环境是怎样?

感谢,给你添麻烦了。如果能写一个compile.sh就更好了。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.