mirror of https://github.com/v2ray/v2ray-core
commit
0f72967854
|
@ -187,6 +187,15 @@ func (c *udpConn) Write(buf []byte) (int, error) {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements buf.ActivityNotifiable
|
||||||
|
func (c *udpConn) NotifyActivity() error {
|
||||||
|
if c.done.Done() {
|
||||||
|
return newError("connection is already closed")
|
||||||
|
}
|
||||||
|
c.updateActivity()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *udpConn) Close() error {
|
func (c *udpConn) Close() error {
|
||||||
common.Must(c.done.Close())
|
common.Must(c.done.Close())
|
||||||
common.Must(common.Close(c.writer))
|
common.Must(common.Close(c.writer))
|
||||||
|
|
|
@ -8,6 +8,11 @@ import (
|
||||||
"v2ray.com/core/common/signal"
|
"v2ray.com/core/common/signal"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ActivityNotifiable is a object that accepts activity notification outside the object
|
||||||
|
type ActivityNotifiable interface {
|
||||||
|
NotifyActivity() error
|
||||||
|
}
|
||||||
|
|
||||||
type dataHandler func(MultiBuffer)
|
type dataHandler func(MultiBuffer)
|
||||||
|
|
||||||
type copyHandler struct {
|
type copyHandler struct {
|
||||||
|
@ -31,6 +36,15 @@ func UpdateActivity(timer signal.ActivityUpdater) CopyOption {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NotifyActivity is a CopyOption to notify activity on each data copy operation.
|
||||||
|
func NotifyActivity(notifier ActivityNotifiable) CopyOption {
|
||||||
|
return func(handler *copyHandler) {
|
||||||
|
handler.onData = append(handler.onData, func(MultiBuffer) {
|
||||||
|
notifier.NotifyActivity()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CountSize is a CopyOption that sums the total size of data copied into the given SizeCounter.
|
// CountSize is a CopyOption that sums the total size of data copied into the given SizeCounter.
|
||||||
func CountSize(sc *SizeCounter) CopyOption {
|
func CountSize(sc *SizeCounter) CopyOption {
|
||||||
return func(handler *copyHandler) {
|
return func(handler *copyHandler) {
|
||||||
|
|
|
@ -164,6 +164,10 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
||||||
|
|
||||||
writer = &buf.SequentialWriter{Writer: tConn}
|
writer = &buf.SequentialWriter{Writer: tConn}
|
||||||
tReader := buf.NewPacketReader(tConn)
|
tReader := buf.NewPacketReader(tConn)
|
||||||
|
notify, ok := conn.(buf.ActivityNotifiable)
|
||||||
|
if !ok {
|
||||||
|
panic("conn should implement ActivityNotifiable")
|
||||||
|
}
|
||||||
requestCount++
|
requestCount++
|
||||||
tproxyRequest = func() error {
|
tproxyRequest = func() error {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -171,7 +175,7 @@ func (d *DokodemoDoor) Process(ctx context.Context, network net.Network, conn in
|
||||||
timer.SetTimeout(plcy.Timeouts.DownlinkOnly)
|
timer.SetTimeout(plcy.Timeouts.DownlinkOnly)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if err := buf.Copy(tReader, link.Writer, buf.UpdateActivity(timer)); err != nil {
|
if err := buf.Copy(tReader, link.Writer, buf.UpdateActivity(timer), buf.NotifyActivity(notify)); err != nil {
|
||||||
return newError("failed to transport request (TPROXY conn)").Base(err)
|
return newError("failed to transport request (TPROXY conn)").Base(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue