Browse Source

Add `PaddingTamarawBulk` tuned for symmetric bulk transfer.

Part of #2.
Yawning Angel 3 years ago
parent
commit
72f203e133
4 changed files with 23 additions and 13 deletions
  1. 2 2
      basket2proxy/main.go
  2. 1 1
      basket2proxy/server.go
  3. 8 3
      common.go
  4. 12 7
      padding_tamaraw.go

+ 2 - 2
basket2proxy/main.go

@@ -176,9 +176,9 @@ func overridePaddingMethods(s string, isClient bool) error {
 		// unless the admin knows what they are doing.
 		for _, m := range enabledPaddingMethods {
 			switch m {
-			case basket2.PaddingNull, basket2.PaddingTamaraw:
+			case basket2.PaddingNull, basket2.PaddingTamaraw, basket2.PaddingTamarawBulk:
 				// PaddingNull - Unobfuscated.
-				// PaddingTamaraw - Extreme overhead.
+				// PaddingTamaraw, PaddingTamarawBulk - Extreme overhead.
 			case basket2.PaddingObfs4PacketIAT:
 				// PaddingObfs4PacketIAT - Clients should use it if available,
 				//   servers should not offer it by default.

+ 1 - 1
basket2proxy/server.go

@@ -179,7 +179,7 @@ func (s *serverState) savePaddingParams(paramsFile string) error {
 
 func (s *serverState) getPaddingParams(method basket2.PaddingMethod) ([]byte, error) {
 	switch method {
-	case basket2.PaddingNull, basket2.PaddingTamaraw:
+	case basket2.PaddingNull, basket2.PaddingTamaraw, basket2.PaddingTamarawBulk:
 		// These algorithms are unparameterized.
 		return nil, nil
 	default:

+ 8 - 3
common.go

@@ -79,6 +79,7 @@ var (
 	ErrNotSupported = errors.New("basket2: operation not supported")
 
 	supportedPaddingMethods = []PaddingMethod{
+		PaddingTamarawBulk,
 		PaddingTamaraw,
 		PaddingObfs4PacketIAT,
 		PaddingObfs4BurstIAT,
@@ -129,6 +130,8 @@ func (m PaddingMethod) ToString() string {
 		return "Obfs4PacketIAT"
 	case PaddingTamaraw:
 		return "Tamaraw"
+	case PaddingTamarawBulk:
+		return "TamarawBulk"
 	default:
 		return "[Unknown algorithm]"
 	}
@@ -148,6 +151,8 @@ func PaddingMethodFromString(s string) PaddingMethod {
 		return PaddingObfs4PacketIAT
 	case "Tamaraw":
 		return PaddingTamaraw
+	case "TamarawBulk":
+		return PaddingTamarawBulk
 	default:
 		return PaddingInvalid
 	}
@@ -408,8 +413,8 @@ func (c *commonConn) setPadding(method PaddingMethod, params []byte) error {
 		if err != nil {
 			return err
 		}
-	case PaddingTamaraw:
-		c.impl = newTamarawPadding(c, c.isClient)
+	case PaddingTamaraw, PaddingTamarawBulk:
+		c.impl = newTamarawPadding(c, method, c.isClient)
 	default:
 		return ErrInvalidPadding
 	}
@@ -547,7 +552,7 @@ func paddingOk(needle PaddingMethod, haystack []PaddingMethod) bool {
 // padding method that requires parameterization.
 func DefaultPaddingParams(method PaddingMethod) ([]byte, error) {
 	switch method {
-	case PaddingNull, PaddingTamaraw:
+	case PaddingNull, PaddingTamaraw, PaddingTamarawBulk:
 		return nil, nil
 	case PaddingObfs4Burst, PaddingObfs4BurstIAT, PaddingObfs4PacketIAT:
 		return obfs4PaddingDefaultParams(method)

+ 12 - 7
padding_tamaraw.go

@@ -43,6 +43,10 @@ const (
 	// primarily interested in things like web browsing, and that the
 	// link MTU is 1500 bytes.
 	PaddingTamaraw PaddingMethod = 0xf0
+
+	// PaddingTamarawBulk is a variant of PaddingTamaraw with parameters
+	// that are tuned for bulk transport in both directions.
+	PaddingTamarawBulk PaddingMethod = 0xf1
 )
 
 type tamarawPadding struct {
@@ -205,7 +209,7 @@ func (p *tamarawPadding) OnClose() {
 
 }
 
-func newTamarawPadding(conn *commonConn, isClient bool) paddingImpl {
+func newTamarawPadding(conn *commonConn, method PaddingMethod, isClient bool) paddingImpl {
 	p := new(tamarawPadding)
 	p.conn = conn
 	p.sendChan = make(chan []byte, 64)
@@ -215,6 +219,7 @@ func newTamarawPadding(conn *commonConn, isClient bool) paddingImpl {
 		}
 	}
 	p.conn.enforceRecordSize = true
+	p.conn.enableReadDelay = true
 
 	// The thesis that evaluates this suggests:
 	//
@@ -228,7 +233,7 @@ func newTamarawPadding(conn *commonConn, isClient bool) paddingImpl {
 	// Lseg = 100 gives a maximum attacker accuracy of 0.59, while 500
 	// reduces that to ~0.35.
 
-	if isClient {
+	if isClient && method != PaddingTamarawBulk {
 		// Tune for "short infrequent bursts".
 		//
 		// The CS-BuFLO's early termination feature suggests that the tail
@@ -243,11 +248,11 @@ func newTamarawPadding(conn *commonConn, isClient bool) paddingImpl {
 		p.lPpad = p.conn.maxRecordSize // Could lower it by 2 for PPPoE links.
 		p.lSeg = 100
 
-		// Random read side delivery jitter.
-		p.conn.enableReadDelay = true
-
-		// Clamp acceptable packets to the client side lPpad value.
-		p.conn.maxRecordSize = 543
+		// Server side specific tunables.
+		if !isClient && method == PaddingTamaraw {
+			// Clamp acceptable packets to the client side lPpad value.
+			p.conn.maxRecordSize = 543
+		}
 	}
 
 	p.Add(1)