mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 15:44:01 +03:00
Add support of EventDomainFronting event
This commit is contained in:
+3
-3
@@ -9,7 +9,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type connTelegramTraffic struct {
|
||||
type connTraffic struct {
|
||||
net.Conn
|
||||
|
||||
connID string
|
||||
@@ -17,7 +17,7 @@ type connTelegramTraffic struct {
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func (c connTelegramTraffic) Read(b []byte) (int, error) {
|
||||
func (c connTraffic) Read(b []byte) (int, error) {
|
||||
n, err := c.Conn.Read(b)
|
||||
|
||||
if n > 0 {
|
||||
@@ -32,7 +32,7 @@ func (c connTelegramTraffic) Read(b []byte) (int, error) {
|
||||
return n, err // nolint: wrapcheck
|
||||
}
|
||||
|
||||
func (c connTelegramTraffic) Write(b []byte) (int, error) {
|
||||
func (c connTraffic) Write(b []byte) (int, error) {
|
||||
n, err := c.Conn.Write(b)
|
||||
|
||||
if n > 0 {
|
||||
|
||||
@@ -62,6 +62,19 @@ func (e EventFinish) Timestamp() time.Time {
|
||||
return e.CreatedAt
|
||||
}
|
||||
|
||||
type EventDomainFronting struct {
|
||||
CreatedAt time.Time
|
||||
ConnID string
|
||||
}
|
||||
|
||||
func (e EventDomainFronting) StreamID() string {
|
||||
return e.ConnID
|
||||
}
|
||||
|
||||
func (e EventDomainFronting) Timestamp() time.Time {
|
||||
return e.CreatedAt
|
||||
}
|
||||
|
||||
type EventConcurrencyLimited struct {
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
@@ -58,6 +58,16 @@ func (suite *EventsTestSuite) TestEventTraffic() {
|
||||
suite.WithinDuration(time.Now(), evt.Timestamp(), 10*time.Millisecond)
|
||||
}
|
||||
|
||||
func (suite *EventsTestSuite) TestEventDomainFronting() {
|
||||
evt := mtglib.EventDomainFronting{
|
||||
CreatedAt: time.Now(),
|
||||
ConnID: "CONNID",
|
||||
}
|
||||
|
||||
suite.Equal("CONNID", evt.StreamID())
|
||||
suite.WithinDuration(time.Now(), evt.Timestamp(), 10*time.Millisecond)
|
||||
}
|
||||
|
||||
func (suite *EventsTestSuite) TestEventConcurrencyLimited() {
|
||||
evt := mtglib.EventConcurrencyLimited{
|
||||
CreatedAt: time.Now(),
|
||||
|
||||
+14
-2
@@ -215,7 +215,7 @@ func (p *Proxy) doTelegramCall(ctx *streamContext) error {
|
||||
}
|
||||
|
||||
ctx.telegramConn = obfuscated2.Conn{
|
||||
Conn: connTelegramTraffic{
|
||||
Conn: connTraffic{
|
||||
Conn: conn,
|
||||
connID: ctx.connID,
|
||||
stream: p.eventStream,
|
||||
@@ -235,7 +235,12 @@ func (p *Proxy) doTelegramCall(ctx *streamContext) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Proxy) doDomainFronting(ctx context.Context, conn *connRewind) {
|
||||
func (p *Proxy) doDomainFronting(ctx *streamContext, conn *connRewind) {
|
||||
p.eventStream.Send(p.ctx, EventDomainFronting{
|
||||
CreatedAt: time.Now(),
|
||||
ConnID: ctx.connID,
|
||||
})
|
||||
|
||||
conn.Rewind()
|
||||
|
||||
frontConn, err := p.network.DialContext(ctx, "tcp", p.domainFrontAddress)
|
||||
@@ -245,6 +250,13 @@ func (p *Proxy) doDomainFronting(ctx context.Context, conn *connRewind) {
|
||||
return
|
||||
}
|
||||
|
||||
frontConn = connTraffic{
|
||||
Conn: frontConn,
|
||||
ctx: ctx,
|
||||
connID: ctx.connID,
|
||||
stream: p.eventStream,
|
||||
}
|
||||
|
||||
rel := relay.AcquireRelay(ctx,
|
||||
p.logger.Named("domain-fronting"), p.bufferSize, p.idleTimeout)
|
||||
defer relay.ReleaseRelay(rel)
|
||||
|
||||
Reference in New Issue
Block a user