代码拉取完成,页面将自动刷新
package remotedialer
import (
"context"
"net/http"
"time"
"github.com/gorilla/websocket"
"github.com/sirupsen/logrus"
)
type ConnectAuthorizer func(proto, address string) bool
func ClientConnect(wsURL string, headers http.Header, dialer *websocket.Dialer, auth ConnectAuthorizer, onConnect func(context.Context) error) {
if err := connectToProxy(wsURL, headers, auth, dialer, onConnect); err != nil {
logrus.WithError(err).Error("Failed to connect to proxy")
time.Sleep(time.Duration(5) * time.Second)
}
}
func connectToProxy(proxyURL string, headers http.Header, auth ConnectAuthorizer, dialer *websocket.Dialer, onConnect func(context.Context) error) error {
logrus.WithField("url", proxyURL).Info("Connecting to proxy")
if dialer == nil {
dialer = &websocket.Dialer{}
}
ws, _, err := dialer.Dial(proxyURL, headers)
if err != nil {
logrus.WithError(err).Error("Failed to connect to proxy")
return err
}
defer ws.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if onConnect != nil {
if err := onConnect(ctx); err != nil {
return err
}
}
session := newClientSession(auth, ws)
_, err = session.serve()
session.Close()
return err
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。