本文整理汇总了Golang中github.com/v2ray/v2ray-core/common/retry.Timed函数的典型用法代码示例。如果您正苦于以下问题:Golang Timed函数的具体用法?Golang Timed怎么用?Golang Timed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Timed函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Dispatch
func (this *FreedomConnection) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) error {
log.Info("Freedom: Opening connection to ", firstPacket.Destination())
var conn net.Conn
err := retry.Timed(5, 100).On(func() error {
rawConn, err := dialer.Dial(firstPacket.Destination())
if err != nil {
return err
}
conn = rawConn
return nil
})
if err != nil {
close(ray.OutboundOutput())
log.Error("Freedom: Failed to open connection to ", firstPacket.Destination(), ": ", err)
return err
}
defer conn.Close()
input := ray.OutboundInput()
output := ray.OutboundOutput()
var readMutex, writeMutex sync.Mutex
readMutex.Lock()
writeMutex.Lock()
if chunk := firstPacket.Chunk(); chunk != nil {
conn.Write(chunk.Value)
chunk.Release()
}
if !firstPacket.MoreChunks() {
writeMutex.Unlock()
} else {
go func() {
v2io.ChanToRawWriter(conn, input)
writeMutex.Unlock()
}()
}
go func() {
defer readMutex.Unlock()
defer close(output)
var reader io.Reader = conn
if firstPacket.Destination().IsUDP() {
reader = v2net.NewTimeOutReader(16 /* seconds */, conn)
}
v2io.RawReaderToChan(output, reader)
}()
writeMutex.Lock()
if tcpConn, ok := conn.(*net.TCPConn); ok {
tcpConn.CloseWrite()
}
readMutex.Lock()
return nil
}
开发者ID:orvice,项目名称:v2ray-core,代码行数:60,代码来源:freedom.go
示例2: refresh
func (this *InboundDetourHandlerDynamic) refresh() error {
this.lastRefresh = time.Now()
for _, ich := range this.ich2Recycle {
port2Delete := ich.Port()
ich.Close()
err := retry.Timed(100 /* times */, 1000 /* ms */).On(func() error {
port := this.pickUnusedPort()
err := ich.Listen(port)
if err != nil {
log.Error("Point: Failed to start inbound detour on port ", port, ": ", err)
return err
}
this.portsInUse[port] = true
return nil
})
if err != nil {
continue
}
delete(this.portsInUse, port2Delete)
}
this.Lock()
this.ich2Recycle, this.ichInUse = this.ichInUse, this.ich2Recycle
this.Unlock()
return nil
}
开发者ID:wangyou,项目名称:v2ray-core,代码行数:30,代码来源:inbound_detour_dynamic.go
示例3: 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("Invalid port ", this.port)
return BadConfiguration
}
err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
err := this.ich.Listen(this.port)
if err != nil {
return err
}
log.Warning("Point server 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
}
开发者ID:jun0205,项目名称:v2ray-core,代码行数:29,代码来源:point.go
示例4: Dispatch
func (this *VMessOutboundHandler) Dispatch(target v2net.Destination, payload *alloc.Buffer, ray ray.OutboundRay) error {
defer ray.OutboundInput().Release()
defer ray.OutboundOutput().Close()
var rec *protocol.ServerSpec
var conn internet.Connection
err := retry.Timed(5, 100).On(func() error {
rec = this.serverPicker.PickServer()
rawConn, err := internet.Dial(this.meta.Address, rec.Destination(), this.meta.StreamSettings)
if err != nil {
return err
}
conn = rawConn
return nil
})
if err != nil {
log.Error("VMess|Outbound: Failed to find an available destination:", err)
return err
}
log.Info("VMess|Outbound: Tunneling request to ", target, " via ", rec.Destination)
command := protocol.RequestCommandTCP
if target.IsUDP() {
command = protocol.RequestCommandUDP
}
request := &protocol.RequestHeader{
Version: encoding.Version,
User: rec.PickUser(),
Command: command,
Address: target.Address(),
Port: target.Port(),
Option: protocol.RequestOptionChunkStream,
}
defer conn.Close()
conn.SetReusable(true)
if conn.Reusable() { // Conn reuse may be disabled on transportation layer
request.Option.Set(protocol.RequestOptionConnectionReuse)
}
input := ray.OutboundInput()
output := ray.OutboundOutput()
var requestFinish, responseFinish sync.Mutex
requestFinish.Lock()
responseFinish.Lock()
session := encoding.NewClientSession(protocol.DefaultIDHash)
go this.handleRequest(session, conn, request, payload, input, &requestFinish)
go this.handleResponse(session, conn, request, rec.Destination(), output, &responseFinish)
requestFinish.Lock()
responseFinish.Lock()
return nil
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:59,代码来源:outbound.go
示例5: Start
func (this *InboundDetourHandler) Start() error {
for _, ich := range this.ich {
return retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
err := ich.handler.Listen(ich.port)
if err != nil {
return err
}
return nil
})
}
return nil
}
开发者ID:sign4bill,项目名称:v2ray-core,代码行数:12,代码来源:inbound_detour.go
示例6: AcceptTCPConnections
func (this *DokodemoDoor) AcceptTCPConnections(tcpListener *net.TCPListener) {
for this.accepting {
retry.Timed(100, 100).On(func() error {
connection, err := tcpListener.AcceptTCP()
if err != nil {
log.Error("Dokodemo failed to accept new connections: %v", err)
return err
}
go this.HandleTCPConnection(connection)
return nil
})
}
}
开发者ID:hackiechain,项目名称:v2ray-core,代码行数:13,代码来源:dokodemo.go
示例7: AcceptConnections
func (server *SocksServer) AcceptConnections(listener *net.TCPListener) {
for server.accepting {
retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
connection, err := listener.AcceptTCP()
if err != nil {
log.Error("Socks failed to accept new connection %v", err)
return err
}
go server.HandleConnection(connection)
return nil
})
}
}
开发者ID:kennshi,项目名称:v2ray-core,代码行数:14,代码来源:socks.go
示例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 (vp *Point) Start() error {
if vp.port <= 0 {
log.Error("Invalid port %d", vp.port)
return config.BadConfiguration
}
return retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
err := vp.ich.Listen(vp.port)
if err == nil {
log.Warning("Point server started on port %d", vp.port)
return nil
}
return err
})
}
开发者ID:amazted,项目名称:v2ray-core,代码行数:17,代码来源:point.go
示例9: AcceptConnections
func (handler *VMessInboundHandler) AcceptConnections(listener *net.TCPListener) error {
for handler.accepting {
retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
connection, err := listener.AcceptTCP()
if err != nil {
log.Error("Failed to accpet connection: %s", err.Error())
return err
}
go handler.HandleConnection(connection)
return nil
})
}
return nil
}
开发者ID:XUJiahua,项目名称:v2ray-core,代码行数:15,代码来源:vmessin.go
示例10: Start
// Starts the inbound connection handler.
func (this *InboundDetourHandler) Start() error {
for _, ich := range this.ich {
err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
err := ich.handler.Listen(ich.port)
if err != nil {
log.Error("Failed to start inbound detour on port %d: %v", ich.port, err)
return err
}
return nil
})
if err != nil {
return err
}
}
return nil
}
开发者ID:adoot,项目名称:v2ray-core,代码行数:17,代码来源:inbound_detour.go
示例11: Start
// Starts the inbound connection handler.
func (this *InboundDetourHandlerAlways) Start() error {
for _, ich := range this.ich {
err := retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
err := ich.Start()
if err != nil {
log.Error("Failed to start inbound detour:", err)
return err
}
return nil
})
if err != nil {
return err
}
}
return nil
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:17,代码来源:inbound_detour_always.go
示例12: accept
func (this *HttpProxyServer) accept() {
for this.accepting {
retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
this.Lock()
defer this.Unlock()
if !this.accepting {
return nil
}
tcpConn, err := this.tcpListener.AcceptTCP()
if err != nil {
log.Error("Failed to accept HTTP connection: ", err)
return err
}
go this.handleConnection(tcpConn)
return nil
})
}
}
开发者ID:ibmendoza,项目名称:v2ray-core,代码行数:18,代码来源:http.go
示例13: AcceptConnections
func (this *SocksServer) AcceptConnections() {
for this.accepting {
retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
this.tcpMutex.RLock()
defer this.tcpMutex.RUnlock()
if !this.accepting {
return nil
}
connection, err := this.tcpListener.AcceptTCP()
if err != nil {
log.Error("Socks: failed to accept new connection: ", err)
return err
}
go this.HandleConnection(connection)
return nil
})
}
}
开发者ID:jun0205,项目名称:v2ray-core,代码行数:18,代码来源:socks.go
示例14: AcceptTCPConnections
func (this *DokodemoDoor) AcceptTCPConnections() {
for this.accepting {
retry.Timed(100, 100).On(func() error {
this.tcpMutex.RLock()
defer this.tcpMutex.RUnlock()
if !this.accepting {
return nil
}
connection, err := this.tcpListener.AcceptTCP()
if err != nil {
log.Error("Dokodemo failed to accept new connections: %v", err)
return err
}
go this.HandleTCPConnection(connection)
return nil
})
}
}
开发者ID:ducktsmt,项目名称:v2ray-core,代码行数:18,代码来源:dokodemo.go
示例15: AcceptConnections
func (this *VMessInboundHandler) AcceptConnections() error {
for this.accepting {
retry.Timed(100 /* times */, 100 /* ms */).On(func() error {
this.Lock()
defer this.Unlock()
if !this.accepting {
return nil
}
connection, err := this.listener.AcceptTCP()
if err != nil {
log.Error("Failed to accpet connection: ", err)
return err
}
go this.HandleConnection(connection)
return nil
})
}
return nil
}
开发者ID:airmao,项目名称:v2ray-core,代码行数:20,代码来源:inbound.go
示例16: 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 {
err := retry.Timed(5, 100).On(func() error {
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 {
delete(this.portsInUse, port)
return err
}
err = ich.Start()
if err != nil {
delete(this.portsInUse, port)
return err
}
this.portsInUse[port] = true
newIchs[idx] = ich
return nil
})
if err != nil {
log.Error("Point: Failed to create inbound connection handler: ", err)
return err
}
}
this.Lock()
this.ichs = newIchs
this.Unlock()
return nil
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:37,代码来源:inbound_detour_dynamic.go
示例17: Dispatch
func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload *alloc.Buffer, ray ray.OutboundRay) error {
log.Info("Freedom: Opening connection to ", destination)
defer payload.Release()
defer ray.OutboundInput().Release()
defer ray.OutboundOutput().Close()
var conn internet.Connection
if this.domainStrategy == DomainStrategyUseIP && destination.Address().IsDomain() {
destination = this.ResolveIP(destination)
}
err := retry.Timed(5, 100).On(func() error {
rawConn, err := internet.Dial(this.meta.Address, destination, this.meta.StreamSettings)
if err != nil {
return err
}
conn = rawConn
return nil
})
if err != nil {
log.Warning("Freedom: Failed to open connection to ", destination, ": ", err)
return err
}
defer conn.Close()
input := ray.OutboundInput()
output := ray.OutboundOutput()
var readMutex, writeMutex sync.Mutex
readMutex.Lock()
writeMutex.Lock()
conn.Write(payload.Value)
go func() {
v2writer := v2io.NewAdaptiveWriter(conn)
defer v2writer.Release()
v2io.Pipe(input, v2writer)
writeMutex.Unlock()
}()
go func() {
defer readMutex.Unlock()
var reader io.Reader = conn
timeout := this.timeout
if destination.IsUDP() {
timeout = 16
}
if timeout > 0 {
reader = v2net.NewTimeOutReader(int(timeout) /* seconds */, conn)
}
v2reader := v2io.NewAdaptiveReader(reader)
defer v2reader.Release()
v2io.Pipe(v2reader, output)
ray.OutboundOutput().Close()
}()
writeMutex.Lock()
if tcpConn, ok := conn.(*tcp.RawConnection); ok {
tcpConn.CloseWrite()
}
readMutex.Lock()
return nil
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:69,代码来源:freedom.go
示例18: Dispatch
func (this *FreedomConnection) Dispatch(firstPacket v2net.Packet, ray ray.OutboundRay) error {
log.Info("Freedom: Opening connection to ", firstPacket.Destination())
var conn net.Conn
err := retry.Timed(5, 100).On(func() error {
rawConn, err := dialer.Dial(firstPacket.Destination())
if err != nil {
return err
}
conn = rawConn
return nil
})
if err != nil {
close(ray.OutboundOutput())
log.Error("Freedom: Failed to open connection to ", firstPacket.Destination(), ": ", err)
return err
}
defer conn.Close()
input := ray.OutboundInput()
output := ray.OutboundOutput()
var readMutex, writeMutex sync.Mutex
readMutex.Lock()
writeMutex.Lock()
if chunk := firstPacket.Chunk(); chunk != nil {
conn.Write(chunk.Value)
chunk.Release()
}
if !firstPacket.MoreChunks() {
writeMutex.Unlock()
} else {
go func() {
v2net.ChanToWriter(conn, input)
writeMutex.Unlock()
}()
}
go func() {
defer readMutex.Unlock()
defer close(output)
response, err := v2net.ReadFrom(conn, nil)
log.Info("Freedom receives ", response.Len(), " bytes from ", conn.RemoteAddr())
if response.Len() > 0 {
output <- response
} else {
response.Release()
}
if err != nil {
return
}
if firstPacket.Destination().IsUDP() {
return
}
v2net.ReaderToChan(output, conn)
}()
if this.space.HasDnsCache() {
if firstPacket.Destination().Address().IsDomain() {
domain := firstPacket.Destination().Address().Domain()
addr := conn.RemoteAddr()
switch typedAddr := addr.(type) {
case *net.TCPAddr:
this.space.DnsCache().Add(domain, typedAddr.IP)
case *net.UDPAddr:
this.space.DnsCache().Add(domain, typedAddr.IP)
}
}
}
writeMutex.Lock()
if tcpConn, ok := conn.(*net.TCPConn); ok {
tcpConn.CloseWrite()
}
readMutex.Lock()
return nil
}
开发者ID:ibmendoza,项目名称:v2ray-core,代码行数:81,代码来源:freedom.go
注:本文中的github.com/v2ray/v2ray-core/common/retry.Timed函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论