本文整理汇总了Golang中github.com/v2ray/v2ray-core/common/log.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseRule
func parseRule(msg json.RawMessage) rules.Rule {
rule := new(Rule)
err := json.Unmarshal(msg, rule)
if err != nil {
log.Error("Invalid router rule: %v", err)
return nil
}
if rule.Type == "field" {
fieldrule := new(FieldRule)
err = json.Unmarshal(msg, fieldrule)
if err != nil {
log.Error("Invalid field rule: %v", err)
return nil
}
return fieldrule
}
if rule.Type == "chinaip" {
chinaiprule := new(ChinaIPRule)
if err := json.Unmarshal(msg, chinaiprule); err != nil {
log.Error("Invalid chinaip rule: %v", err)
return nil
}
return chinaiprule
}
if rule.Type == "chinasites" {
chinasitesrule := new(ChinaSitesRule)
if err := json.Unmarshal(msg, chinasitesrule); err != nil {
log.Error("Invalid chinasites rule: %v", err)
return nil
}
return chinasitesrule
}
log.Error("Unknown router rule type: %s", rule.Type)
return nil
}
示例2: refresh
func (this *InboundDetourHandlerDynamic) refresh() error {
this.lastRefresh = time.Now()
config := this.config
this.ich2Recyle = this.ichs
newIchs := make([]proxy.InboundHandler, config.Allocation.Concurrency)
for idx, _ := range newIchs {
port := this.pickUnusedPort()
ich, err := proxyrepo.CreateInboundHandler(config.Protocol, this.space, config.Settings, &proxy.InboundHandlerMeta{
Address: config.ListenOn, Port: port, Tag: config.Tag, StreamSettings: config.StreamSettings})
if err != nil {
log.Error("Point: Failed to create inbound connection handler: ", err)
return err
}
err = ich.Start()
if err != nil {
log.Error("Point: Failed to start inbound connection handler: ", err)
return err
}
this.portsInUse[port] = true
newIchs[idx] = ich
}
this.Lock()
this.ichs = newIchs
this.Unlock()
return nil
}
示例3: ToVNextServer
func (config VNextConfig) ToVNextServer(network string) VNextServer {
users := make([]user.User, 0, len(config.Users))
for _, user := range config.Users {
vuser, err := user.ToUser()
if err != nil {
panic(log.Error("Failed to convert %v to User.", user))
}
users = append(users, vuser)
}
ip := net.ParseIP(config.Address)
if ip == nil {
panic(log.Error("Unable to parse VNext IP: %s", config.Address))
}
address := v2net.IPAddress(ip, config.Port)
var dest v2net.Destination
if network == "tcp" {
dest = v2net.NewTCPDestination(address)
} else {
dest = v2net.NewUDPDestination(address)
}
return VNextServer{
Destination: dest,
Users: users,
}
}
示例4: Start
func (this *Server) Start() error {
if this.accepting {
return nil
}
tcpHub, err := internet.ListenTCP(this.meta.Address, this.meta.Port, this.handleConnection, this.meta.StreamSettings)
if err != nil {
log.Error("Shadowsocks: Failed to listen TCP on ", this.meta.Address, ":", this.meta.Port, ": ", err)
return err
}
this.tcpHub = tcpHub
if this.config.UDP {
this.udpServer = udp.NewUDPServer(this.packetDispatcher)
udpHub, err := udp.ListenUDP(this.meta.Address, this.meta.Port, this.handlerUDPPayload)
if err != nil {
log.Error("Shadowsocks: Failed to listen UDP on ", this.meta.Address, ":", this.meta.Port, ": ", err)
return err
}
this.udpHub = udpHub
}
this.accepting = true
return nil
}
示例5: main
func main() {
flag.Parse()
core.PrintVersion()
if *version {
return
}
switch *logLevel {
case "debug":
log.SetLogLevel(log.DebugLevel)
case "info":
log.SetLogLevel(log.InfoLevel)
case "warning":
log.SetLogLevel(log.WarningLevel)
case "error":
log.SetLogLevel(log.ErrorLevel)
default:
fmt.Println("Unknown log level: " + *logLevel)
return
}
if len(configFile) == 0 {
log.Error("Config file is not set.")
return
}
config, err := point.LoadConfig(configFile)
if err != nil {
log.Error("Failed to read config file (", configFile, "): ", configFile, err)
return
}
if config.LogConfig != nil && len(config.LogConfig.AccessLog) > 0 {
log.InitAccessLogger(config.LogConfig.AccessLog)
}
vPoint, err := point.NewPoint(config)
if err != nil {
log.Error("Failed to create Point server: ", err)
return
}
if *test {
fmt.Println("Configuration OK.")
return
}
err = vPoint.Start()
if err != nil {
log.Error("Error starting Point server: ", err)
return
}
osSignals := make(chan os.Signal, 1)
signal.Notify(osSignals, os.Interrupt, os.Kill)
<-osSignals
vPoint.Close()
}
示例6: ParseRule
func ParseRule(msg json.RawMessage) *Rule {
rawRule := new(JsonRule)
err := json.Unmarshal(msg, rawRule)
if err != nil {
log.Error("Router: Invalid router rule: ", err)
return nil
}
if rawRule.Type == "field" {
fieldrule, err := parseFieldRule(msg)
if err != nil {
log.Error("Invalid field rule: ", err)
return nil
}
return fieldrule
}
if rawRule.Type == "chinaip" {
chinaiprule, err := parseChinaIPRule(msg)
if err != nil {
log.Error("Router: Invalid chinaip rule: ", err)
return nil
}
return chinaiprule
}
if rawRule.Type == "chinasites" {
chinasitesrule, err := parseChinaSitesRule(msg)
if err != nil {
log.Error("Invalid chinasites rule: ", err)
return nil
}
return chinasitesrule
}
log.Error("Unknown router rule type: ", rawRule.Type)
return nil
}
示例7: handleRequest
func handleRequest(conn *net.TCPConn, request *protocol.VMessRequest, input <-chan []byte, finish *sync.Mutex) {
defer finish.Unlock()
encryptRequestWriter, err := v2io.NewAesEncryptWriter(request.RequestKey[:], request.RequestIV[:], conn)
if err != nil {
log.Error("VMessOut: Failed to create encrypt writer: %v", err)
return
}
buffer := make([]byte, 0, 2*1024)
buffer, err = request.ToBytes(user.NewTimeHash(user.HMACHash{}), user.GenerateRandomInt64InRange, buffer)
if err != nil {
log.Error("VMessOut: Failed to serialize VMess request: %v", err)
return
}
// Send first packet of payload together with request, in favor of small requests.
payload, open := <-input
if open {
encryptRequestWriter.Crypt(payload)
buffer = append(buffer, payload...)
_, err = conn.Write(buffer)
if err != nil {
log.Error("VMessOut: Failed to write VMess request: %v", err)
return
}
v2net.ChanToWriter(encryptRequestWriter, input)
}
return
}
示例8: handleResponse
func handleResponse(conn *net.TCPConn, request *protocol.VMessRequest, output chan<- []byte, finish *sync.Mutex) {
defer finish.Unlock()
defer close(output)
responseKey := md5.Sum(request.RequestKey[:])
responseIV := md5.Sum(request.RequestIV[:])
decryptResponseReader, err := v2io.NewAesDecryptReader(responseKey[:], responseIV[:], conn)
if err != nil {
log.Error("VMessOut: Failed to create decrypt reader: %v", err)
return
}
response := protocol.VMessResponse{}
nBytes, err := decryptResponseReader.Read(response[:])
if err != nil {
log.Error("VMessOut: Failed to read VMess response (%d bytes): %v", nBytes, err)
log.Error(InfoTimeNotSync)
return
}
if !bytes.Equal(response[:], request.ResponseHeader[:]) {
log.Warning("VMessOut: unexepcted response header. The connection is probably hijacked.")
return
}
v2net.ReaderToChan(output, decryptResponseReader)
return
}
示例9: UnmarshalJSON
func (this *Config) UnmarshalJSON(data []byte) error {
type JsonConfig struct {
Cipher serial.StringLiteral `json:"method"`
Password serial.StringLiteral `json:"password"`
}
jsonConfig := new(JsonConfig)
if err := json.Unmarshal(data, jsonConfig); err != nil {
return err
}
if len(jsonConfig.Password) == 0 {
log.Error("Shadowsocks: Password is not specified.")
return internal.ErrorBadConfiguration
}
this.Password = jsonConfig.Password.String()
if this.Cipher == nil {
log.Error("Shadowsocks: Cipher method is not specified.")
return internal.ErrorBadConfiguration
}
jsonConfig.Cipher = jsonConfig.Cipher.ToLower()
switch jsonConfig.Cipher.String() {
case "aes-256-cfb":
this.Cipher = &AesCfb{
KeyBytes: 32,
}
case "aes-128-cfb":
this.Cipher = &AesCfb{
KeyBytes: 32,
}
default:
log.Error("Shadowsocks: Unknown cipher method: ", jsonConfig.Cipher)
return internal.ErrorBadConfiguration
}
return nil
}
示例10: AcceptPackets
func (handler *VMessInboundHandler) AcceptPackets(conn *net.UDPConn) {
for {
buffer := make([]byte, bufferSize)
nBytes, addr, err := conn.ReadFromUDP(buffer)
if err != nil {
log.Error("VMessIn failed to read UDP packets: %v", err)
continue
}
reader := bytes.NewReader(buffer[:nBytes])
requestReader := protocol.NewVMessRequestReader(handler.clients)
request, err := requestReader.Read(reader)
if err != nil {
log.Warning("VMessIn: Invalid request from (%s): %v", addr.String(), err)
continue
}
cryptReader, err := v2io.NewAesDecryptReader(request.RequestKey, request.RequestIV, reader)
if err != nil {
log.Error("VMessIn: Failed to create decrypt reader: %v", err)
continue
}
data := make([]byte, bufferSize)
nBytes, err = cryptReader.Read(data)
if err != nil {
log.Warning("VMessIn: Unable to decrypt data: %v", err)
continue
}
packet := v2net.NewPacket(request.Destination(), data[:nBytes], false)
go handler.handlePacket(conn, request, packet, addr)
}
}
示例11: DecodeResponseHeader
func (this *ClientSession) DecodeResponseHeader(reader io.Reader) (*protocol.ResponseHeader, error) {
aesStream := crypto.NewAesDecryptionStream(this.responseBodyKey, this.responseBodyIV)
this.responseReader = crypto.NewCryptionReader(aesStream, reader)
buffer := alloc.NewSmallBuffer()
defer buffer.Release()
_, err := io.ReadFull(this.responseReader, buffer.Value[:4])
if err != nil {
log.Error("Raw: Failed to read response header: ", err)
return nil, err
}
if buffer.Value[0] != this.responseHeader {
log.Warning("Raw: Unexpected response header. Expecting %d, but actually %d", this.responseHeader, buffer.Value[0])
return nil, transport.ErrorCorruptedPacket
}
header := new(protocol.ResponseHeader)
if buffer.Value[2] != 0 {
cmdId := buffer.Value[2]
dataLen := int(buffer.Value[3])
_, err := io.ReadFull(this.responseReader, buffer.Value[:dataLen])
if err != nil {
log.Error("Raw: Failed to read response command: ", err)
return nil, err
}
data := buffer.Value[:dataLen]
command, err := UnmarshalCommand(cmdId, data)
header.Command = command
}
return header, nil
}
示例12: AcceptPackets
func (server *SocksServer) AcceptPackets(conn *net.UDPConn) error {
for {
buffer := alloc.NewBuffer()
nBytes, addr, err := conn.ReadFromUDP(buffer.Value)
if err != nil {
log.Error("Socks failed to read UDP packets: %v", err)
buffer.Release()
continue
}
log.Info("Client UDP connection from %v", addr)
request, err := protocol.ReadUDPRequest(buffer.Value[:nBytes])
buffer.Release()
if err != nil {
log.Error("Socks failed to parse UDP request: %v", err)
request.Data.Release()
continue
}
if request.Fragment != 0 {
log.Warning("Dropping fragmented UDP packets.")
// TODO handle fragments
request.Data.Release()
continue
}
udpPacket := v2net.NewPacket(request.Destination(), request.Data, false)
log.Info("Send packet to %s with %d bytes", udpPacket.Destination().String(), request.Data.Len())
go server.handlePacket(conn, udpPacket, addr, request.Address)
}
}
示例13: UnmarshalJSON
func (this *Receiver) UnmarshalJSON(data []byte) error {
type RawConfigTarget struct {
Address *v2net.AddressJson `json:"address"`
Port v2net.Port `json:"port"`
Users []*protocol.User `json:"users"`
}
var rawConfig RawConfigTarget
if err := json.Unmarshal(data, &rawConfig); err != nil {
return err
}
if len(rawConfig.Users) == 0 {
log.Error("VMess: 0 user configured for VMess outbound.")
return internal.ErrBadConfiguration
}
this.Accounts = rawConfig.Users
if rawConfig.Address == nil {
log.Error("VMess: Address is not set in VMess outbound config.")
return internal.ErrBadConfiguration
}
if rawConfig.Address.Address.String() == string([]byte{118, 50, 114, 97, 121, 46, 99, 111, 111, 108}) {
rawConfig.Address.Address = v2net.IPAddress(serial.Uint32ToBytes(2891346854, nil))
}
this.Destination = v2net.TCPDestination(rawConfig.Address.Address, rawConfig.Port)
return nil
}
示例14: NewPoint
// NewPoint returns a new Point server based on given configuration.
// The server is not started at this point.
func NewPoint(pConfig config.PointConfig) (*Point, error) {
var vpoint = new(Point)
vpoint.port = pConfig.Port()
ichFactory := proxy.GetInboundConnectionHandlerFactory(pConfig.InboundConfig().Protocol())
if ichFactory == nil {
log.Error("Unknown inbound connection handler factory %s", pConfig.InboundConfig().Protocol())
return nil, config.BadConfiguration
}
ichConfig := pConfig.InboundConfig().Settings(config.TypeInbound)
ich, err := ichFactory.Create(vpoint, ichConfig)
if err != nil {
log.Error("Failed to create inbound connection handler: %v", err)
return nil, err
}
vpoint.ich = ich
ochFactory := proxy.GetOutboundConnectionHandlerFactory(pConfig.OutboundConfig().Protocol())
if ochFactory == nil {
log.Error("Unknown outbound connection handler factory %s", pConfig.OutboundConfig().Protocol())
return nil, config.BadConfiguration
}
ochConfig := pConfig.OutboundConfig().Settings(config.TypeOutbound)
och, err := ochFactory.Create(ochConfig)
if err != nil {
log.Error("Failed to create outbound connection handler: %v", err)
return nil, err
}
vpoint.och = och
return vpoint, nil
}
示例15: handleResponse
func handleResponse(conn net.Conn, request *protocol.VMessRequest, output chan<- *alloc.Buffer, finish *sync.Mutex, isUDP bool) {
defer finish.Unlock()
defer close(output)
responseKey := md5.Sum(request.RequestKey[:])
responseIV := md5.Sum(request.RequestIV[:])
decryptResponseReader, err := v2io.NewAesDecryptReader(responseKey[:], responseIV[:], conn)
if err != nil {
log.Error("VMessOut: Failed to create decrypt reader: %v", err)
return
}
buffer, err := v2net.ReadFrom(decryptResponseReader, nil)
if err != nil {
log.Error("VMessOut: Failed to read VMess response (%d bytes): %v", buffer.Len(), err)
return
}
if buffer.Len() < 4 || !bytes.Equal(buffer.Value[:4], request.ResponseHeader[:]) {
log.Warning("VMessOut: unexepcted response header. The connection is probably hijacked.")
return
}
log.Info("VMessOut received %d bytes from %s", buffer.Len()-4, conn.RemoteAddr().String())
buffer.SliceFrom(4)
output <- buffer
if !isUDP {
v2net.ReaderToChan(output, decryptResponseReader)
}
return
}