Add support of EventDomainFronting event

This commit is contained in:
9seconds
2021-03-29 11:56:05 +03:00
parent 36d695118e
commit bef14bd009
17 changed files with 317 additions and 53 deletions
+3 -3
View File
@@ -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 {
+13
View File
@@ -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
}
+10
View File
@@ -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
View File
@@ -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)