-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13614c0
commit 60aa6d9
Showing
5 changed files
with
125 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package mux | ||
|
||
import ( | ||
"encoding/binary" | ||
|
||
"github.com/sagernet/sing/common/buf" | ||
M "github.com/sagernet/sing/common/metadata" | ||
N "github.com/sagernet/sing/common/network" | ||
) | ||
|
||
var _ N.PacketReadWaiter = (*clientPacketConn)(nil) | ||
|
||
func (c *clientPacketConn) InitializeReadWaiter(options N.ReadWaitOptions) (needCopy bool) { | ||
c.readWaitOptions = options | ||
return false | ||
} | ||
|
||
func (c *clientPacketConn) WaitReadPacket() (buffer *buf.Buffer, destination M.Socksaddr, err error) { | ||
if !c.responseRead { | ||
err = c.readResponse() | ||
if err != nil { | ||
return | ||
} | ||
c.responseRead = true | ||
} | ||
var length uint16 | ||
err = binary.Read(c.conn, binary.BigEndian, &length) | ||
if err != nil { | ||
return | ||
} | ||
buffer = c.readWaitOptions.NewPacketBuffer() | ||
_, err = buffer.ReadFullFrom(c.conn, int(length)) | ||
if err != nil { | ||
buffer.Release() | ||
return nil, M.Socksaddr{}, err | ||
} | ||
c.readWaitOptions.PostReturn(buffer) | ||
return | ||
} | ||
|
||
var _ N.PacketReadWaiter = (*clientPacketAddrConn)(nil) | ||
|
||
func (c *clientPacketAddrConn) InitializeReadWaiter(options N.ReadWaitOptions) (needCopy bool) { | ||
c.readWaitOptions = options | ||
return false | ||
} | ||
|
||
func (c *clientPacketAddrConn) WaitReadPacket() (buffer *buf.Buffer, destination M.Socksaddr, err error) { | ||
if !c.responseRead { | ||
err = c.readResponse() | ||
if err != nil { | ||
return | ||
} | ||
c.responseRead = true | ||
} | ||
destination, err = M.SocksaddrSerializer.ReadAddrPort(c.conn) | ||
if err != nil { | ||
return | ||
} | ||
var length uint16 | ||
err = binary.Read(c.conn, binary.BigEndian, &length) | ||
if err != nil { | ||
return | ||
} | ||
buffer = c.readWaitOptions.NewPacketBuffer() | ||
_, err = buffer.ReadFullFrom(c.conn, int(length)) | ||
if err != nil { | ||
buffer.Release() | ||
return nil, M.Socksaddr{}, err | ||
} | ||
c.readWaitOptions.PostReturn(buffer) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters