Process 处理IP
(ip string)
| 69 | |
| 70 | // Process 处理IP |
| 71 | func (this *Queue) Process(ip string) error { |
| 72 | // 是否已经在库中 |
| 73 | if SharedManager.ContainsIP(ip) { |
| 74 | return nil |
| 75 | } |
| 76 | |
| 77 | ptr, err := this.ParseIP(ip) |
| 78 | if err != nil { |
| 79 | return err |
| 80 | } |
| 81 | if len(ptr) == 0 || ptr == "." { |
| 82 | return nil |
| 83 | } |
| 84 | |
| 85 | //remotelogs.Debug("AGENT", ip+" => "+ptr) |
| 86 | |
| 87 | var agentCode = this.ParsePtr(ptr) |
| 88 | if len(agentCode) == 0 { |
| 89 | return nil |
| 90 | } |
| 91 | |
| 92 | // 加入到本地 |
| 93 | SharedManager.AddIP(ip, agentCode) |
| 94 | |
| 95 | var pbAgentIP = &pb.CreateClientAgentIPsRequest_AgentIPInfo{ |
| 96 | AgentCode: agentCode, |
| 97 | Ip: ip, |
| 98 | Ptr: ptr, |
| 99 | } |
| 100 | rpcClient, err := rpc.SharedRPC() |
| 101 | if err != nil { |
| 102 | return err |
| 103 | } |
| 104 | _, err = rpcClient.ClientAgentIPRPC.CreateClientAgentIPs(rpcClient.Context(), &pb.CreateClientAgentIPsRequest{AgentIPs: []*pb.CreateClientAgentIPsRequest_AgentIPInfo{pbAgentIP}}) |
| 105 | if err != nil { |
| 106 | return err |
| 107 | } |
| 108 | |
| 109 | return nil |
| 110 | } |
| 111 | |
| 112 | // ParseIP 分析IP的PTR值 |
| 113 | func (this *Queue) ParseIP(ip string) (ptr string, err error) { |