本文整理汇总了Golang中v2ray/com/core/common/log.Warning函数的典型用法代码示例。如果您正苦于以下问题:Golang Warning函数的具体用法?Golang Warning怎么用?Golang Warning使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Warning函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ListenUDP
func ListenUDP(address v2net.Address, port v2net.Port, option ListenOption) (*UDPHub, error) {
if option.Concurrency < 1 {
option.Concurrency = 1
}
udpConn, err := net.ListenUDP("udp", &net.UDPAddr{
IP: address.IP(),
Port: int(port),
})
if err != nil {
return nil, err
}
if option.ReceiveOriginalDest {
fd, err := internal.GetSysFd(udpConn)
if err != nil {
log.Warning("UDP|Listener: Failed to get fd: ", err)
return nil, err
}
err = SetOriginalDestOptions(fd)
if err != nil {
log.Warning("UDP|Listener: Failed to set socket options: ", err)
return nil, err
}
}
hub := &UDPHub{
conn: udpConn,
queue: NewUDPPayloadQueue(option),
option: option,
cancel: signal.NewCloseSignal(),
}
go hub.start()
return hub, nil
}
示例2: Process
func (s *Server) Process(ctx context.Context, network v2net.Network, conn internet.Connection) error {
conn.SetReusable(false)
timedReader := v2net.NewTimeOutReader(s.config.Timeout, conn)
reader := bufio.OriginalReaderSize(timedReader, 2048)
request, err := http.ReadRequest(reader)
if err != nil {
if errors.Cause(err) != io.EOF {
log.Warning("HTTP: Failed to read http request: ", err)
}
return err
}
log.Info("HTTP: Request to Method [", request.Method, "] Host [", request.Host, "] with URL [", request.URL, "]")
defaultPort := v2net.Port(80)
if strings.ToLower(request.URL.Scheme) == "https" {
defaultPort = v2net.Port(443)
}
host := request.Host
if len(host) == 0 {
host = request.URL.Host
}
dest, err := parseHost(host, defaultPort)
if err != nil {
log.Warning("HTTP: Malformed proxy host (", host, "): ", err)
return err
}
log.Access(conn.RemoteAddr(), request.URL, log.AccessAccepted, "")
ctx = proxy.ContextWithDestination(ctx, dest)
if strings.ToUpper(request.Method) == "CONNECT" {
return s.handleConnect(ctx, request, reader, conn)
} else {
return s.handlePlainHTTP(ctx, request, reader, conn)
}
}
示例3: ListenUDP
func ListenUDP(address v2net.Address, port v2net.Port, option ListenOption) (*UDPHub, error) {
udpConn, err := net.ListenUDP("udp", &net.UDPAddr{
IP: address.IP(),
Port: int(port),
})
if err != nil {
return nil, err
}
if option.ReceiveOriginalDest {
fd, err := internal.GetSysFd(udpConn)
if err != nil {
log.Warning("UDP|Listener: Failed to get fd: ", err)
return nil, err
}
err = SetOriginalDestOptions(fd)
if err != nil {
log.Warning("UDP|Listener: Failed to set socket options: ", err)
return nil, err
}
}
hub := &UDPHub{
conn: udpConn,
option: option,
}
go hub.start()
return hub, nil
}
示例4: parseIP
func parseIP(s string) *router.CIDR {
var addr, mask string
i := strings.Index(s, "/")
if i < 0 {
addr = s
} else {
addr = s[:i]
mask = s[i+1:]
}
ip := v2net.ParseAddress(addr)
switch ip.Family() {
case v2net.AddressFamilyIPv4:
bits := uint32(32)
if len(mask) > 0 {
bits64, err := strconv.ParseUint(mask, 10, 32)
if err != nil {
return nil
}
bits = uint32(bits64)
}
if bits > 32 {
log.Warning("Router: invalid network mask: ", bits)
return nil
}
return &router.CIDR{
Ip: []byte(ip.IP()),
Prefix: bits,
}
case v2net.AddressFamilyIPv6:
bits := uint32(128)
if len(mask) > 0 {
bits64, err := strconv.ParseUint(mask, 10, 32)
if err != nil {
return nil
}
bits = uint32(bits64)
}
if bits > 128 {
log.Warning("Router: invalid network mask: ", bits)
return nil
}
return &router.CIDR{
Ip: []byte(ip.IP()),
Prefix: bits,
}
default:
log.Warning("Router: unsupported address: ", s)
return nil
}
}
示例5: generateCommand
func (v *VMessInboundHandler) generateCommand(ctx context.Context, request *protocol.RequestHeader) protocol.ResponseCommand {
if v.detours != nil {
tag := v.detours.To
if v.inboundHandlerManager != nil {
handler, err := v.inboundHandlerManager.GetHandler(ctx, tag)
if err != nil {
log.Warning("VMess|Inbound: Failed to get detour handler: ", tag, err)
return nil
}
proxyHandler, port, availableMin := handler.GetRandomInboundProxy()
inboundHandler, ok := proxyHandler.(*VMessInboundHandler)
if ok {
if availableMin > 255 {
availableMin = 255
}
log.Info("VMessIn: Pick detour handler for port ", port, " for ", availableMin, " minutes.")
user := inboundHandler.GetUser(request.User.Email)
if user == nil {
return nil
}
account, _ := user.GetTypedAccount()
return &protocol.CommandSwitchAccount{
Port: port,
ID: account.(*vmess.InternalAccount).ID.UUID(),
AlterIds: uint16(len(account.(*vmess.InternalAccount).AlterIDs)),
Level: user.Level,
ValidMin: byte(availableMin),
}
}
}
}
return nil
}
示例6: Dial
func Dial(src v2net.Address, dest v2net.Destination, options internet.DialerOptions) (internet.Connection, error) {
log.Info("WebSocket|Dailer: Creating connection to ", dest)
if src == nil {
src = v2net.AnyIP
}
networkSettings, err := options.Stream.GetEffectiveNetworkSettings()
if err != nil {
return nil, err
}
wsSettings := networkSettings.(*Config)
id := src.String() + "-" + dest.NetAddr()
var conn *wsconn
if dest.Network == v2net.Network_TCP && wsSettings.ConnectionReuse.IsEnabled() {
connt := globalCache.Get(id)
if connt != nil {
conn = connt.(*wsconn)
}
}
if conn == nil {
var err error
conn, err = wsDial(src, dest, options)
if err != nil {
log.Warning("WebSocket|Dialer: Dial failed: ", err)
return nil, err
}
}
return NewConnection(id, conn, globalCache, wsSettings), nil
}
示例7: DispatchToOutbound
func (this *DefaultDispatcher) DispatchToOutbound(meta *proxy.InboundHandlerMeta, session *proxy.SessionInfo) ray.InboundRay {
direct := ray.NewRay()
dispatcher := this.ohm.GetDefaultHandler()
destination := session.Destination
if this.router != nil {
if tag, err := this.router.TakeDetour(destination); err == nil {
if handler := this.ohm.GetHandler(tag); handler != nil {
log.Info("DefaultDispatcher: Taking detour [", tag, "] for [", destination, "].")
dispatcher = handler
} else {
log.Warning("DefaultDispatcher: Nonexisting tag: ", tag)
}
} else {
log.Info("DefaultDispatcher: Default route for ", destination)
}
}
if meta.AllowPassiveConnection {
go dispatcher.Dispatch(destination, alloc.NewLocalBuffer(32).Clear(), direct)
} else {
go this.FilterPacketAndDispatch(destination, direct, dispatcher)
}
return direct
}
示例8: Start
// Start starts the Point server, and return any error during the process.
// In the case of any errors, the state of the server is unpredicatable.
func (this *Point) Start() error {
if this.port <= 0 {
log.Error("Point: Invalid port ", this.port)
return common.ErrBadConfiguration
}
err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
err := this.ich.Start()
if err != nil {
return err
}
log.Warning("Point: started on port ", this.port)
return nil
})
if err != nil {
return err
}
for _, detourHandler := range this.idh {
err := detourHandler.Start()
if err != nil {
return err
}
}
return nil
}
示例9: ListenTCP
func ListenTCP(address v2net.Address, port v2net.Port, callback ConnectionHandler, settings *StreamConfig) (*TCPHub, error) {
var listener Listener
var err error
options := ListenOptions{
Stream: settings,
}
switch settings.Network {
case v2net.Network_TCP:
listener, err = TCPListenFunc(address, port, options)
case v2net.Network_KCP:
listener, err = KCPListenFunc(address, port, options)
case v2net.Network_WebSocket:
listener, err = WSListenFunc(address, port, options)
case v2net.Network_RawTCP:
listener, err = RawTCPListenFunc(address, port, options)
default:
log.Error("Internet|Listener: Unknown stream type: ", settings.Network)
err = ErrUnsupportedStreamType
}
if err != nil {
log.Warning("Internet|Listener: Failed to listen on ", address, ":", port)
return nil, err
}
hub := &TCPHub{
listener: listener,
connCallback: callback,
}
go hub.start()
return hub, nil
}
示例10: handleConnection
func (v *Server) handleConnection(connection internet.Connection) {
defer connection.Close()
timedReader := v2net.NewTimeOutReader(v.config.Timeout, connection)
reader := bufio.NewReader(timedReader)
defer reader.Release()
writer := bufio.NewWriter(connection)
defer writer.Release()
auth, auth4, err := protocol.ReadAuthentication(reader)
if err != nil && errors.Cause(err) != protocol.Socks4Downgrade {
if errors.Cause(err) != io.EOF {
log.Warning("Socks: failed to read authentication: ", err)
}
return
}
clientAddr := v2net.DestinationFromAddr(connection.RemoteAddr())
if err != nil && err == protocol.Socks4Downgrade {
v.handleSocks4(clientAddr, reader, writer, auth4)
} else {
v.handleSocks5(clientAddr, reader, writer, auth)
}
}
示例11: handleSocks4
func (v *Server) handleSocks4(clientAddr v2net.Destination, reader *bufio.BufferedReader, writer *bufio.BufferedWriter, auth protocol.Socks4AuthenticationRequest) error {
result := protocol.Socks4RequestGranted
if auth.Command == protocol.CmdBind {
result = protocol.Socks4RequestRejected
}
socks4Response := protocol.NewSocks4AuthenticationResponse(result, auth.Port, auth.IP[:])
socks4Response.Write(writer)
if result == protocol.Socks4RequestRejected {
log.Warning("Socks: Unsupported socks 4 command ", auth.Command)
log.Access(clientAddr, "", log.AccessRejected, ErrUnsupportedSocksCommand)
return ErrUnsupportedSocksCommand
}
reader.SetCached(false)
writer.SetCached(false)
dest := v2net.TCPDestination(v2net.IPAddress(auth.IP[:]), auth.Port)
session := &proxy.SessionInfo{
Source: clientAddr,
Destination: dest,
Inbound: v.meta,
}
log.Access(clientAddr, dest, log.AccessAccepted, "")
v.transport(reader, writer, session)
return nil
}
示例12: handleResponse
func (v *VMessOutboundHandler) handleResponse(session *encoding.ClientSession, conn internet.Connection, request *protocol.RequestHeader, dest v2net.Destination, output buf.Writer, finish *sync.Mutex) {
defer finish.Unlock()
reader := bufio.NewReader(conn)
defer reader.Release()
header, err := session.DecodeResponseHeader(reader)
if err != nil {
conn.SetReusable(false)
log.Warning("VMess|Outbound: Failed to read response from ", request.Destination(), ": ", err)
return
}
v.handleCommand(dest, header.Command)
conn.SetReusable(header.Option.Has(protocol.ResponseOptionConnectionReuse))
reader.SetCached(false)
bodyReader := session.DecodeResponseBody(request, reader)
defer bodyReader.Release()
if err := buf.PipeUntilEOF(bodyReader, output); err != nil {
conn.SetReusable(false)
}
return
}
示例13: Dial
func (h *Handler) Dial(ctx context.Context, dest v2net.Destination) (internet.Connection, error) {
if h.senderSettings != nil {
if h.senderSettings.ProxySettings.HasTag() {
tag := h.senderSettings.ProxySettings.Tag
handler := h.outboundManager.GetHandler(tag)
if handler != nil {
log.Info("Proxyman|OutboundHandler: Proxying to ", tag)
ctx = proxy.ContextWithDestination(ctx, dest)
stream := ray.NewRay(ctx)
go handler.Dispatch(ctx, stream)
return NewConnection(stream), nil
}
log.Warning("Proxyman|OutboundHandler: Failed to get outbound handler with tag: ", tag)
}
if h.senderSettings.Via != nil {
ctx = internet.ContextWithDialerSource(ctx, h.senderSettings.Via.AsAddress())
}
if h.senderSettings != nil {
ctx = internet.ContextWithStreamSettings(ctx, h.senderSettings.StreamSettings)
}
}
return internet.Dial(ctx, dest)
}
示例14: DispatchToOutbound
func (v *DefaultDispatcher) DispatchToOutbound(session *proxy.SessionInfo) ray.InboundRay {
direct := ray.NewRay()
dispatcher := v.ohm.GetDefaultHandler()
destination := session.Destination
if v.router != nil {
if tag, err := v.router.TakeDetour(session); err == nil {
if handler := v.ohm.GetHandler(tag); handler != nil {
log.Info("DefaultDispatcher: Taking detour [", tag, "] for [", destination, "].")
dispatcher = handler
} else {
log.Warning("DefaultDispatcher: Nonexisting tag: ", tag)
}
} else {
log.Info("DefaultDispatcher: Default route for ", destination)
}
}
if session.Inbound != nil && session.Inbound.AllowPassiveConnection {
go dispatcher.Dispatch(destination, buf.NewLocal(32), direct)
} else {
go v.FilterPacketAndDispatch(destination, direct, dispatcher)
}
return direct
}
示例15: handlePlainHTTP
func (this *Server) handlePlainHTTP(request *http.Request, session *proxy.SessionInfo, reader *bufio.Reader, writer io.Writer) {
if len(request.URL.Host) <= 0 {
response := this.GenerateResponse(400, "Bad Request")
response.Write(writer)
return
}
request.Host = request.URL.Host
StripHopByHopHeaders(request)
ray := this.packetDispatcher.DispatchToOutbound(session)
defer ray.InboundInput().Close()
defer ray.InboundOutput().Release()
var finish sync.WaitGroup
finish.Add(1)
go func() {
defer finish.Done()
requestWriter := v2io.NewBufferedWriter(v2io.NewChainWriter(ray.InboundInput()))
err := request.Write(requestWriter)
if err != nil {
log.Warning("HTTP: Failed to write request: ", err)
return
}
requestWriter.Flush()
}()
finish.Add(1)
go func() {
defer finish.Done()
responseReader := bufio.NewReader(v2io.NewChanReader(ray.InboundOutput()))
response, err := http.ReadResponse(responseReader, request)
if err != nil {
log.Warning("HTTP: Failed to read response: ", err)
response = this.GenerateResponse(503, "Service Unavailable")
}
responseWriter := v2io.NewBufferedWriter(writer)
err = response.Write(responseWriter)
if err != nil {
log.Warning("HTTP: Failed to write response: ", err)
return
}
responseWriter.Flush()
}()
finish.Wait()
}