Coder Social home page Coder Social logo

easyproxy's Introduction

EasyProxy

A simple proxy server.

Introduction

+----------+                                           +------------+
|  client  |<--------+                                 |            |
+----------+         +-------->+-----+<--------------->|   server   |
                               |     |                 |            |
+----------+                   |     |                 +------------+
|  client  |<----------------->|     |
+----------+                   |     |
                               |     |                 +------------+
+----------+                   |  L  |                 |            |
|  client  |<----------------->|  B  |<--------------->|   server   |
+----------+                   |  S  |                 |            |
                               |     |                 +------------+
+----------+                   |     |
|  client  |<----------------->|     |
+----------+                   |     |                 +------------+
                               |     |                 |            |
+----------+        +--------->+-----+<--------------->|   server   |
|  client  |<-------+                                  |            |
+----------+                                           +------------+

As the chart above, easyproxy act as the LBS server. If you meet the situation that cannot access some service directly or need a server as a gateway, you may use this to proxy.

Usage

go get github.com/xsank/EasyProxy
go run build.go build
  • The sample config is about mysql proxy, so you can access the mysql database actually at backend through the localhost 9527, you can easily modify the default.json to change the service. Any protocol based on TCP would work well such as:mysql, ssh, svn...
  • For keep simple, easyproxy only support poll,random,iphash strategies, and the default strategy is poll,the easyproxy would add more if there is a demand.
  • Besides, you can curl localhost:7259/statistic to get the current connection status. If you want to know more runtime debug info about the proxy, you can curl http://localhost:7259/debug/pprof to get more details.
  • You can change the number of MAX processorsand and the heartbeat time based on your requirements.

License

Easyproxy is distributed under MIT License.

easyproxy's People

Contributors

xsank 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

easyproxy's Issues

svn协议连接异常

我是用这个来代理连接到svn服务器,比如svn://localhost:9999,启动proxy后,连接不过去,后台还保持了好几个连接到背后的svn服务器,可能是我通过9999端口访问的时候关掉了,
1.但是proxy与svn之间的连接没断开。
2.ctrl+c 关不掉程序
3.svn协议的不行?

关于easyproxy

您好,这个工程的主要功能,使用场景还有如何使用的能描述下么,谢谢

if Backends is empty, the proxy will be panic

panic: runtime error: integer divide by zero
[signal 0x8 code=0x1 addr=0x5b9d29 pc=0x5b9d29]

goroutine 9 [running]:
panic(0x7c8020, 0xc82000a0f0)
/usr/lib/golang/src/runtime/panic.go:481 +0x3e6
github.com/xsank/EasyProxy/src/proxy/schedule.(*Poll).Choose(0xc82000b260, 0xc82000bfd0, 0xf, 0xa7ce70, 0x0, 0x0, 0xc8200118c0, 0xc820011800)
/vagrant/.gopath/src/github.com/xsank/EasyProxy/src/proxy/schedule/poll.go:12 +0x49
github.com/xsank/EasyProxy/src/proxy.(*EasyProxy).Dispatch(0xc8200aca00, 0x7f00e89faa70, 0xc820022088)
/vagrant/.gopath/src/github.com/xsank/EasyProxy/src/proxy/esay_proxy.go:64 +0x11c
created by github.com/xsank/EasyProxy/src/gateway.(*ProxyServer).Start
/vagrant/.gopath/src/github.com/xsank/EasyProxy/src/gateway/server.go:46 +0x3ed
exit status 2

小白过来问个问题

func (proxy *EasyProxy) Dispatch(conn net.Conn) {
	if proxy.isBackendAvailable() {
		servers := proxy.data.BackendUrls()
                // 这里不是特别懂,为啥选出这个url呢?
		url := proxy.strategy.Choose(conn.RemoteAddr().String(), servers)
		proxy.transfer(conn, url)
	} else {
		conn.Close()
		log.Println("no backend available now,please check your server!")
	}
}

func (proxy *EasyProxy) transfer(local net.Conn, remote string) {
	remoteConn, err := net.DialTimeout("tcp", remote, DefaultTimeOut*time.Second)
	if err != nil {
		local.Close()
		proxy.Clean(remote)
		log.Println("connect backend err", err)
		return
	}
	sync := make(chan int)
	channel := &structure.Channel{Src: local, Dst: remoteConn}
	go proxy.putChannel(channel)
	go proxy.safeCopy(local, remoteConn, sync)
	go proxy.safeCopy(remoteConn, local, sync)
	go proxy.closeChannel(channel, sync)
}

我的理解,proxy.strategy.Choose 会在backend随机选择一个对应的backend server来做连接,为啥这里strategy是随机的,不是应该和conn对应对应的吗? 谢谢大佬帮忙解答一下

EasyProxy用的都是短连接

remoteConn, err := net.DialTimeout("tcp", remote, DefaultTimeoutTime * time.Second)
if err != nil {
	local.Close()
	proxy.Clean(remote)
	log.Println("connect backend error:%s", err)
	return
}
sync := make(chan int, 1)
channel := structure.Channel{SrcConn:local, DstConn:remoteConn}
go proxy.putChannel(&channel)
go proxy.safeCopy(local, remoteConn, sync)
go proxy.safeCopy(remoteConn, local, sync)
go proxy.closeChannel(&channel, sync)

Multi-threads safety

Both ChannelManager and ProxyData are multi-threads unsafe, so why not protect those append or delete operations to the same slice or map from different goroutines with sync.Mutex?

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.