Skip to content

Commit

Permalink
add new command
Browse files Browse the repository at this point in the history
  • Loading branch information
ixqbar committed Sep 17, 2018
1 parent 7ce0192 commit 4fe848d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions src/proxy/fcgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand All @@ -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
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/proxy/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 4fe848d

Please sign in to comment.