예제 #1
0
파일: paas.go 프로젝트: yinqiwen/gsnova
func (p *PaasProxy) Init(conf proxy.ProxyChannelConfig) error {
	p.conf = conf
	p.cs = proxy.NewRemoteChannelTable()
	paasHttpClient, err := proxy.NewHTTPClient(&p.conf)
	if nil != err {
		return err
	}
	for _, server := range conf.ServerList {
		for i := 0; i < conf.ConnsPerServer; i++ {
			var channel *proxy.RemoteChannel
			var err error
			if strings.HasPrefix(server, "ws://") || strings.HasPrefix(server, "wss://") {
				channel, err = newWebsocketChannel(server, i, conf, paasHttpClient.Transport.(*http.Transport).Dial)
			} else if strings.HasPrefix(server, "http://") || strings.HasPrefix(server, "https://") {
				channel, err = newHTTPChannel(server, i, paasHttpClient, conf)
			} else {
				err = fmt.Errorf("Not supported url:%s", server)
			}
			if nil != err {
				log.Printf("[ERROR]Failed to connect [%d]%s for reason:%v", i, server, err)
				if i == 0 {
					return fmt.Errorf("Failed to auth %s", server)
				}
				continue
			}
			if nil != channel {
				p.cs.Add(channel)
			}
		}
	}
	return nil
}
예제 #2
0
파일: gae.go 프로젝트: yinqiwen/gsnova
func (p *GAEProxy) Init(conf proxy.ProxyChannelConfig) error {
	p.conf = conf
	p.cs = proxy.NewRemoteChannelTable()
	hc := initGAEClient(conf)
	for _, server := range conf.ServerList {
		channel, err := newHTTPChannel(server, hc, conf)
		if nil != err {
			log.Printf("[ERROR]Failed to connect %s for reason:%v", server, err)
			continue
		}
		if nil != channel {
			p.cs.Add(channel)
		}
	}
	//p.injectRangeRegex, _ = proxy.NewRegex(conf.InjectRange)
	return nil
}
예제 #3
0
파일: vps.go 프로젝트: yinqiwen/gsnova
func (p *VPSProxy) Init(conf proxy.ProxyChannelConfig) error {
	p.cs = proxy.NewRemoteChannelTable()
	for _, server := range conf.ServerList {
		for i := 0; i < conf.ConnsPerServer; i++ {
			if !strings.Contains(server, "://") {
				server = "tcp://" + server
			}
			channel, err := newTCPChannel(server, i, conf)
			if nil != channel {
				p.cs.Add(channel)
			} else {
				log.Printf("Failed to init proxy channel for %s:%d with reason:%v", server, i, err)
				if i == 0 {
					return fmt.Errorf("Failed to auth %s", server)
				}
			}
		}
	}
	p.conf = conf
	return nil
}