-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into stable
- Loading branch information
Showing
22 changed files
with
328 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package antireplay | ||
|
||
type nilCache struct{} | ||
|
||
func (n nilCache) AddObfuscated2(_ []byte) {} | ||
func (n nilCache) AddTLS(_ []byte) {} | ||
func (n nilCache) HasObfuscated2(_ []byte) bool { return false } | ||
func (n nilCache) HasTLS(_ []byte) bool { return false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package faketls | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"sync" | ||
"time" | ||
|
||
"github.com/9seconds/mtg/wrappers/rwc" | ||
) | ||
|
||
const ( | ||
cloakLastActivityTimeout = 5 * time.Second | ||
cloakMaxTimeout = 30 * time.Second | ||
) | ||
|
||
func cloak(one, another io.ReadWriteCloser) { | ||
defer func() { | ||
one.Close() | ||
another.Close() | ||
}() | ||
|
||
channelPing := make(chan struct{}, 1) | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
one = rwc.NewPing(ctx, one, channelPing) | ||
another = rwc.NewPing(ctx, another, channelPing) | ||
wg := &sync.WaitGroup{} | ||
|
||
wg.Add(2) | ||
|
||
go func() { | ||
defer wg.Done() | ||
io.Copy(one, another) // nolint: errcheck | ||
}() | ||
|
||
go func() { | ||
defer wg.Done() | ||
io.Copy(another, one) // nolint: errcheck | ||
}() | ||
|
||
go func() { | ||
wg.Wait() | ||
cancel() | ||
}() | ||
|
||
go func() { | ||
lastActivityTimer := time.NewTimer(cloakLastActivityTimeout) | ||
defer lastActivityTimer.Stop() | ||
|
||
maxTimer := time.NewTimer(cloakMaxTimeout) | ||
defer maxTimer.Stop() | ||
|
||
for { | ||
select { | ||
case <-channelPing: | ||
lastActivityTimer.Stop() | ||
lastActivityTimer = time.NewTimer(cloakLastActivityTimeout) | ||
case <-ctx.Done(): | ||
return | ||
case <-lastActivityTimer.C: | ||
cancel() | ||
return | ||
case <-maxTimer.C: | ||
cancel() | ||
return | ||
} | ||
} | ||
}() | ||
|
||
<-ctx.Done() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.