From 4fe848dd154539c0341d3be62e1a38f75069278b Mon Sep 17 00:00:00 2001 From: xingqiba Date: Mon, 17 Sep 2018 14:18:02 +0800 Subject: [PATCH] add new command --- README.md | 3 ++- src/proxy/client.go | 8 +++++++- src/proxy/fcgi.go | 22 ++++++++++++++-------- src/proxy/redis.go | 10 ++++++++++ 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4b08059..f034fef 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,8 @@ tpush * {"title":"php发送的","message":"just for test"} #推送消息给iOS a atoken {name} {token} #刷新android推送对应name的token -addfcgiserver 192.168.1.100:9000 #增加fcgi server +addfcgiserver 192.168.1.100:9000 #增加fcgi server +removefcgiserver 192.168.1.100:9000 #删除fcgi server ``` * rpush用于接收爬虫扫到的代理服务器,用于qpush推送使用 * rpush对应爬虫可以参考 https://github.com/jonnywang/sockslistnet diff --git a/src/proxy/client.go b/src/proxy/client.go index 2852675..c504f60 100644 --- a/src/proxy/client.go +++ b/src/proxy/client.go @@ -152,11 +152,17 @@ func (obj *Client) PipeReadMessage() { continue } + fcgiServer := GFcgiServer.GetServer() + if len(fcgiServer) == 0 { + Logger.Print("no available fcgiserver to post") + continue + } + body.Reset(messageContent) startTime := time.Now() - fcgi, err := fcgiclient.Dial("tcp", GFcgiServer.GetServer()) + fcgi, err := fcgiclient.Dial("tcp", fcgiServer) if err != nil { Logger.Print(err) break diff --git a/src/proxy/fcgi.go b/src/proxy/fcgi.go index d32b2e9..807cfb5 100644 --- a/src/proxy/fcgi.go +++ b/src/proxy/fcgi.go @@ -28,7 +28,12 @@ func (obj *FcgiServer) GetServer() string { obj.Lock() defer obj.Unlock() - i := rand.Intn(len(obj.address)) + l := len(obj.address) + if l == 0 { + return "" + } + + i := rand.Intn(l) Logger.Printf("select fcgi server %s to post", obj.address[i]) @@ -55,14 +60,15 @@ func (obj *FcgiServer) RemoveServer(server string) bool { defer obj.Unlock() l := len(obj.address) - - for k, v := range obj.address { - if v == server { - if k != l-1 { - obj.address[k] = obj.address[l-1] + if l > 0 { + for k, v := range obj.address { + if v == server { + if k != l-1 { + obj.address[k] = obj.address[l-1] + } + obj.address = obj.address[:l-1] + return true } - obj.address = obj.address[:l-1] - break } } diff --git a/src/proxy/redis.go b/src/proxy/redis.go index 66bffc0..187d5ab 100644 --- a/src/proxy/redis.go +++ b/src/proxy/redis.go @@ -239,6 +239,16 @@ func (obj *FcgiRedisHandle) AddFcgiServer(server string) error { return nil } +func (obj *FcgiRedisHandle) RemoveFcgiServer(server string) error { + if len(server) == 0 || strings.Index(server,":") == -1 { + return ERR_PARAMS + } + + GFcgiServer.RemoveServer(server) + + return nil +} + var FcgiRedis = &FcgiRedisHandle{} func Run() {