glider/proxy/proxy.go

47 lines
982 B
Go
Raw Permalink Normal View History

package proxy
2022-03-13 18:03:10 +08:00
import (
"net"
"strings"
)
2020-09-24 18:50:04 +08:00
// Proxy is a dialer manager.
type Proxy interface {
// Dial connects to the given address via the proxy.
Dial(network, addr string) (c net.Conn, dialer Dialer, err error)
// DialUDP connects to the given address via the proxy.
DialUDP(network, addr string) (pc net.PacketConn, dialer UDPDialer, err error)
// Get the dialer by dstAddr.
NextDialer(dstAddr string) Dialer
// Record records result while using the dialer from proxy.
Record(dialer Dialer, success bool)
}
2022-03-13 18:03:10 +08:00
2022-03-14 13:06:26 +08:00
var (
msg strings.Builder
usages = make(map[string]string)
)
2022-03-13 18:03:10 +08:00
// AddUsage adds help message for the named proxy.
2022-03-14 13:06:26 +08:00
func AddUsage(name, usage string) {
usages[name] = usage
msg.WriteString(usage)
msg.WriteString("\n--")
}
2022-03-13 18:03:10 +08:00
// Usage returns help message of the named proxy.
func Usage(name string) string {
if name == "all" {
return msg.String()
}
if usage, ok := usages[name]; ok {
return usage
}
return "can not find usage for: " + name
}