func (self *DialerPool) Dial(network, hostport string) (net.Conn, error) { host := utils.GetHost(hostport) //o(n) maybe a little slow:) for _, dial := range self.pool { for _, ipnet := range dial.ipnets { if ipnet.Contains(net.ParseIP(host)) == false { continue } return dial.dialer.Dial(network, hostport) } } glog.Infoln("cannot found any ipnet for ", host) for _, dial := range self.pool { return dial.dialer.Dial(network, hostport) } return nil, utils.ErrEmptyDialerPool }
func (self *DialerPool) Get(hostport string) proxy.Dialer { host := utils.GetHost(hostport) if host == "" { for _, dial := range self.pool { return dial.dialer } } //o(n) maybe a little slow:) for _, dial := range self.pool { for _, ipnet := range dial.ipnets { if ipnet.Contains(net.ParseIP(host)) == false { continue } return dial.dialer } } glog.Infoln("cannot found any ipnet for ", host) for _, dial := range self.pool { return dial.dialer } return nil }