@@ -75,28 +75,12 @@ type Server interface {
75
75
// LatencyRx returns current receive latency.
76
76
LatencyRx () time.Duration
77
77
78
- // ModifyTx alters/corrupts/drops "outgoing" packets from the listener
79
- // with the given edit function.
80
- ModifyTx (f func (data []byte ) []byte )
81
- // UnmodifyTx removes modify operation on "forwarding".
82
- UnmodifyTx ()
83
-
84
- // ModifyRx alters/corrupts/drops "incoming" packets to client
85
- // with the given edit function.
86
- ModifyRx (f func (data []byte ) []byte )
87
- // UnmodifyRx removes modify operation on "receiving".
88
- UnmodifyRx ()
89
-
90
78
// BlackholeTx drops all "outgoing" packets before "forwarding".
91
- // "BlackholeTx" operation is a wrapper around "ModifyTx" with
92
- // a function that returns empty bytes.
93
79
BlackholeTx ()
94
80
// UnblackholeTx removes blackhole operation on "sending".
95
81
UnblackholeTx ()
96
82
97
83
// BlackholeRx drops all "incoming" packets to client.
98
- // "BlackholeRx" operation is a wrapper around "ModifyRx" with
99
- // a function that returns empty bytes.
100
84
BlackholeRx ()
101
85
// UnblackholeRx removes blackhole operation on "receiving".
102
86
UnblackholeRx ()
@@ -140,11 +124,11 @@ type server struct {
140
124
listenerMu sync.RWMutex
141
125
listener net.Listener
142
126
143
- modifyTxMu sync.RWMutex
144
- modifyTx func ( data [] byte ) [] byte
127
+ shouldDropTxMu sync.RWMutex
128
+ shouldDropTx bool
145
129
146
- modifyRxMu sync.RWMutex
147
- modifyRx func ( data [] byte ) [] byte
130
+ shouldDropRxMu sync.RWMutex
131
+ shouldDropRx bool
148
132
149
133
pauseTxMu sync.Mutex
150
134
pauseTxc chan struct {}
@@ -404,20 +388,20 @@ func (s *server) ioCopy(dst io.Writer, src io.Reader, ptype proxyType) {
404
388
}
405
389
data := buf [:nr1 ]
406
390
407
- // alters/corrupts/ drops data
391
+ // drops data
408
392
switch ptype {
409
393
case proxyTx :
410
- s .modifyTxMu .RLock ()
411
- if s .modifyTx != nil {
412
- data = s . modifyTx ( data )
394
+ s .shouldDropTxMu .RLock ()
395
+ if s .shouldDropTx {
396
+ data = nil
413
397
}
414
- s .modifyTxMu .RUnlock ()
398
+ s .shouldDropTxMu .RUnlock ()
415
399
case proxyRx :
416
- s .modifyRxMu .RLock ()
417
- if s .modifyRx != nil {
418
- data = s . modifyRx ( data )
400
+ s .shouldDropRxMu .RLock ()
401
+ if s .shouldDropRx {
402
+ data = nil
419
403
}
420
- s .modifyRxMu .RUnlock ()
404
+ s .shouldDropRxMu .RUnlock ()
421
405
default :
422
406
panic ("unknown proxy type" )
423
407
}
@@ -691,55 +675,56 @@ func computeLatency(lat, rv time.Duration) time.Duration {
691
675
return lat + time .Duration (int64 (sign )* mrand .Int63n (rv .Nanoseconds ()))
692
676
}
693
677
694
- func (s * server ) ModifyTx ( f func ([] byte ) [] byte ) {
695
- s .modifyTxMu .Lock ()
696
- s .modifyTx = f
697
- s .modifyTxMu .Unlock ()
678
+ func (s * server ) setShouldDropTx ( ) {
679
+ s .shouldDropTxMu .Lock ()
680
+ s .shouldDropTx = true
681
+ s .shouldDropTxMu .Unlock ()
698
682
699
683
s .lg .Info (
700
- "modifying tx " ,
684
+ "setShouldDropTx " ,
701
685
zap .String ("from" , s .From ()),
702
686
zap .String ("to" , s .To ()),
703
687
)
704
688
}
705
689
706
- func (s * server ) UnmodifyTx () {
707
- s .modifyTxMu .Lock ()
708
- s .modifyTx = nil
709
- s .modifyTxMu .Unlock ()
690
+ func (s * server ) unsetShouldDropTx () {
691
+ s .shouldDropTxMu .Lock ()
692
+ s .shouldDropTx = false
693
+ s .shouldDropTxMu .Unlock ()
710
694
711
695
s .lg .Info (
712
- "unmodifyed tx " ,
696
+ "unsetShouldDropTx " ,
713
697
zap .String ("from" , s .From ()),
714
698
zap .String ("to" , s .To ()),
715
699
)
716
700
}
717
701
718
- func (s * server ) ModifyRx (f func ([]byte ) []byte ) {
719
- s .modifyRxMu .Lock ()
720
- s .modifyRx = f
721
- s .modifyRxMu .Unlock ()
702
+ func (s * server ) setShouldDropRx () {
703
+ s .shouldDropRxMu .Lock ()
704
+ s .shouldDropRx = true
705
+ s .shouldDropRxMu .Unlock ()
706
+
722
707
s .lg .Info (
723
- "modifying rx " ,
724
- zap .String ("from" , s .To ()),
725
- zap .String ("to" , s .From ()),
708
+ "setShouldDropRx " ,
709
+ zap .String ("from" , s .From ()),
710
+ zap .String ("to" , s .To ()),
726
711
)
727
712
}
728
713
729
- func (s * server ) UnmodifyRx () {
730
- s .modifyRxMu .Lock ()
731
- s .modifyRx = nil
732
- s .modifyRxMu .Unlock ()
714
+ func (s * server ) unsetShouldDropRx () {
715
+ s .shouldDropRxMu .Lock ()
716
+ s .shouldDropRx = false
717
+ s .shouldDropRxMu .Unlock ()
733
718
734
719
s .lg .Info (
735
- "unmodifyed rx " ,
736
- zap .String ("from" , s .To ()),
737
- zap .String ("to" , s .From ()),
720
+ "unsetShouldDropRx " ,
721
+ zap .String ("from" , s .From ()),
722
+ zap .String ("to" , s .To ()),
738
723
)
739
724
}
740
725
741
726
func (s * server ) BlackholeTx () {
742
- s .ModifyTx ( func ([] byte ) [] byte { return nil } )
727
+ s .setShouldDropTx ( )
743
728
s .lg .Info (
744
729
"blackholed tx" ,
745
730
zap .String ("from" , s .From ()),
@@ -748,7 +733,7 @@ func (s *server) BlackholeTx() {
748
733
}
749
734
750
735
func (s * server ) UnblackholeTx () {
751
- s .UnmodifyTx ()
736
+ s .unsetShouldDropTx ()
752
737
s .lg .Info (
753
738
"unblackholed tx" ,
754
739
zap .String ("from" , s .From ()),
@@ -757,7 +742,7 @@ func (s *server) UnblackholeTx() {
757
742
}
758
743
759
744
func (s * server ) BlackholeRx () {
760
- s .ModifyRx ( func ([] byte ) [] byte { return nil } )
745
+ s .setShouldDropRx ( )
761
746
s .lg .Info (
762
747
"blackholed rx" ,
763
748
zap .String ("from" , s .To ()),
@@ -766,7 +751,7 @@ func (s *server) BlackholeRx() {
766
751
}
767
752
768
753
func (s * server ) UnblackholeRx () {
769
- s .UnmodifyRx ()
754
+ s .unsetShouldDropRx ()
770
755
s .lg .Info (
771
756
"unblackholed rx" ,
772
757
zap .String ("from" , s .To ()),
0 commit comments