1
0
mirror of https://github.com/fumiama/terasu.git synced 2026-06-12 14:10:32 +08:00

feat: new implementations

This commit is contained in:
源文雨
2024-04-19 00:12:45 +09:00
parent b7e45bc58e
commit 719e0c1683
15 changed files with 682 additions and 162 deletions

View File

@@ -6,25 +6,27 @@ import (
"unsafe"
)
var DefaultFirstFragmentLen uint8 = 4
// Use terasu in this TLS conn
func Use(conn *tls.Conn) *Conn {
return (*Conn)(conn)
}
// Handshake do terasu handshake in this TLS conn
func (conn *Conn) Handshake() error {
func (conn *Conn) Handshake(firstFragmentLen uint8) error {
expose := (*_trsconn)(unsafe.Pointer(conn))
fnbak := expose.handshakeFn
expose.handshakeFn = conn.clientHandshake
expose.handshakeFn = conn.clientHandshake(firstFragmentLen)
defer func() { expose.handshakeFn = fnbak }()
return (*tls.Conn)(conn).Handshake()
}
// Handshake do terasu handshake with ctx in this TLS conn
func (conn *Conn) HandshakeContext(ctx context.Context) error {
func (conn *Conn) HandshakeContext(ctx context.Context, firstFragmentLen uint8) error {
expose := (*_trsconn)(unsafe.Pointer(conn))
fnbak := expose.handshakeFn
expose.handshakeFn = conn.clientHandshake
expose.handshakeFn = conn.clientHandshake(firstFragmentLen)
defer func() { expose.handshakeFn = fnbak }()
return (*tls.Conn)(conn).HandshakeContext(ctx)
}