forked from algorand/go-algorand
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tunnel outgoing connection via a rate limiting dialer (algorand#780)
* changes. * adding dialer. * DRAFT: using channel to offload the mutex. * Taking care of the lock triggering deadlock detection. * cleaning unnecessary changes. * cleaning unnecessary changes. * minor fixes * GetNetTransport modifying returning copy of the http.Transport * workaround to avoid the race detection trigger. * Testing a different approach to ovrride the Dial/DialContext by embedding the default transport into another object instead of changing the default transport. * Adding RateLimitedTransport to wrap around the http.Transport * fixing lint * Separating Dialer from Transport, initializing the Dialer and Transport params (timeout, etc) * changes. * Integrating changes from Tsachi + cleanups. * fixing build failure. * fixing build failure. * Addressing Pavel's comments. * changes. * adding dialer. * DRAFT: using channel to offload the mutex. * Taking care of the lock triggering deadlock detection. * cleaning unnecessary changes. * cleaning unnecessary changes. * minor fixes * GetNetTransport modifying returning copy of the http.Transport * workaround to avoid the race detection trigger. * Testing a different approach to ovrride the Dial/DialContext by embedding the default transport into another object instead of changing the default transport. * Adding RateLimitedTransport to wrap around the http.Transport * fixing lint * Separating Dialer from Transport, initializing the Dialer and Transport params (timeout, etc) * changes. * Integrating changes from Tsachi + cleanups. * fixing build failure. * fixing build failure. * Addressing Pavel's comments. * changes. * adding dialer. * DRAFT: using channel to offload the mutex. * Taking care of the lock triggering deadlock detection. * cleaning unnecessary changes. * cleaning unnecessary changes. * minor fixes * GetNetTransport modifying returning copy of the http.Transport * workaround to avoid the race detection trigger. * Testing a different approach to ovrride the Dial/DialContext by embedding the default transport into another object instead of changing the default transport. * Adding RateLimitedTransport to wrap around the http.Transport * fixing lint * Separating Dialer from Transport, initializing the Dialer and Transport params (timeout, etc) * changes. * Integrating changes from Tsachi + cleanups. * fixing build failure. * fixing build failure. * Allow asset creation transactions to be created while catching up. (algorand#790) * Addressing Pavel's comments. * changes. * adding dialer. * DRAFT: using channel to offload the mutex. * Taking care of the lock triggering deadlock detection. * cleaning unnecessary changes. * cleaning unnecessary changes. * minor fixes * GetNetTransport modifying returning copy of the http.Transport * workaround to avoid the race detection trigger. * Testing a different approach to ovrride the Dial/DialContext by embedding the default transport into another object instead of changing the default transport. * Adding RateLimitedTransport to wrap around the http.Transport * fixing lint * Separating Dialer from Transport, initializing the Dialer and Transport params (timeout, etc) * changes. * Integrating changes from Tsachi + cleanups. * fixing build failure. * fixing build failure. * Addressing Pavel's comments. * rebasing master Co-authored-by: Tsachi Herman <tsachi.herman@algorand.com> Co-authored-by: Will Winder <wwinder.unh@gmail.com>
- Loading branch information
1 parent
eb090a0
commit e523a9a
Showing
9 changed files
with
215 additions
and
99 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (C) 2019-2020 Algorand, Inc. | ||
// This file is part of go-algorand | ||
// | ||
// go-algorand is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as | ||
// published by the Free Software Foundation, either version 3 of the | ||
// License, or (at your option) any later version. | ||
// | ||
// go-algorand is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package network | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"time" | ||
) | ||
|
||
// Dialer establish tcp-level connection with the destination | ||
type Dialer struct { | ||
phonebook *MultiPhonebook | ||
innerDialer net.Dialer | ||
} | ||
|
||
// Dial connects to the address on the named network. | ||
// It waits if needed not to exceed connectionsRateLimitingCount. | ||
func (d *Dialer) Dial(network, address string) (net.Conn, error) { | ||
return d.DialContext(context.Background(), network, address) | ||
} | ||
|
||
// DialContext connects to the address on the named network using the provided context. | ||
// It waits if needed not to exceed connectionsRateLimitingCount. | ||
func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) { | ||
var waitTime time.Duration | ||
var provisionalTime time.Time | ||
|
||
for { | ||
_, waitTime, provisionalTime = d.phonebook.GetConnectionWaitTime(address) | ||
if waitTime == 0 { | ||
break // break out of the loop and proceed to the connection | ||
} | ||
select { | ||
case <-ctx.Done(): | ||
return nil, ctx.Err() | ||
case <-time.After(waitTime): | ||
} | ||
} | ||
conn, err := d.innerDialer.DialContext(ctx, network, address) | ||
d.phonebook.UpdateConnectionTime(address, provisionalTime) | ||
|
||
return conn, err | ||
} |
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
Oops, something went wrong.