Commit 17bc04b6 authored by vyzo's avatar vyzo

make DialWorkerFunc, NewDialSync private

they work with private data types, so there is no point in having them public
parent 43b03828
...@@ -13,10 +13,10 @@ import ( ...@@ -13,10 +13,10 @@ import (
var errDialCanceled = errors.New("dial was aborted internally, likely due to https://git.io/Je2wW") var errDialCanceled = errors.New("dial was aborted internally, likely due to https://git.io/Je2wW")
// DialWorerFunc is used by DialSync to spawn a new dial worker // DialWorerFunc is used by DialSync to spawn a new dial worker
type DialWorkerFunc func(context.Context, peer.ID, <-chan dialRequest) error type dialWorkerFunc func(context.Context, peer.ID, <-chan dialRequest) error
// NewDialSync constructs a new DialSync // newDialSync constructs a new DialSync
func NewDialSync(worker DialWorkerFunc) *DialSync { func newDialSync(worker dialWorkerFunc) *DialSync {
return &DialSync{ return &DialSync{
dials: make(map[peer.ID]*activeDial), dials: make(map[peer.ID]*activeDial),
dialWorker: worker, dialWorker: worker,
...@@ -28,7 +28,7 @@ func NewDialSync(worker DialWorkerFunc) *DialSync { ...@@ -28,7 +28,7 @@ func NewDialSync(worker DialWorkerFunc) *DialSync {
type DialSync struct { type DialSync struct {
dials map[peer.ID]*activeDial dials map[peer.ID]*activeDial
dialsLk sync.Mutex dialsLk sync.Mutex
dialWorker DialWorkerFunc dialWorker dialWorkerFunc
} }
type activeDial struct { type activeDial struct {
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
) )
func getMockDialFunc() (DialWorkerFunc, func(), context.Context, <-chan struct{}) { func getMockDialFunc() (dialWorkerFunc, func(), context.Context, <-chan struct{}) {
dfcalls := make(chan struct{}, 512) // buffer it large enough that we won't care dfcalls := make(chan struct{}, 512) // buffer it large enough that we won't care
dialctx, cancel := context.WithCancel(context.Background()) dialctx, cancel := context.WithCancel(context.Background())
ch := make(chan struct{}) ch := make(chan struct{})
...@@ -48,7 +48,7 @@ func getMockDialFunc() (DialWorkerFunc, func(), context.Context, <-chan struct{} ...@@ -48,7 +48,7 @@ func getMockDialFunc() (DialWorkerFunc, func(), context.Context, <-chan struct{}
func TestBasicDialSync(t *testing.T) { func TestBasicDialSync(t *testing.T) {
df, done, _, callsch := getMockDialFunc() df, done, _, callsch := getMockDialFunc()
dsync := NewDialSync(df) dsync := newDialSync(df)
p := peer.ID("testpeer") p := peer.ID("testpeer")
...@@ -86,7 +86,7 @@ func TestBasicDialSync(t *testing.T) { ...@@ -86,7 +86,7 @@ func TestBasicDialSync(t *testing.T) {
func TestDialSyncCancel(t *testing.T) { func TestDialSyncCancel(t *testing.T) {
df, done, _, dcall := getMockDialFunc() df, done, _, dcall := getMockDialFunc()
dsync := NewDialSync(df) dsync := newDialSync(df)
p := peer.ID("testpeer") p := peer.ID("testpeer")
...@@ -137,7 +137,7 @@ func TestDialSyncCancel(t *testing.T) { ...@@ -137,7 +137,7 @@ func TestDialSyncCancel(t *testing.T) {
func TestDialSyncAllCancel(t *testing.T) { func TestDialSyncAllCancel(t *testing.T) {
df, done, dctx, _ := getMockDialFunc() df, done, dctx, _ := getMockDialFunc()
dsync := NewDialSync(df) dsync := newDialSync(df)
p := peer.ID("testpeer") p := peer.ID("testpeer")
...@@ -211,7 +211,7 @@ func TestFailFirst(t *testing.T) { ...@@ -211,7 +211,7 @@ func TestFailFirst(t *testing.T) {
return nil return nil
} }
ds := NewDialSync(f) ds := newDialSync(f)
p := peer.ID("testing") p := peer.ID("testing")
...@@ -234,7 +234,7 @@ func TestFailFirst(t *testing.T) { ...@@ -234,7 +234,7 @@ func TestFailFirst(t *testing.T) {
} }
func TestStressActiveDial(t *testing.T) { func TestStressActiveDial(t *testing.T) {
ds := NewDialSync(func(ctx context.Context, p peer.ID, reqch <-chan dialRequest) error { ds := newDialSync(func(ctx context.Context, p peer.ID, reqch <-chan dialRequest) error {
go func() { go func() {
for { for {
select { select {
...@@ -279,16 +279,14 @@ func TestDialSelf(t *testing.T) { ...@@ -279,16 +279,14 @@ func TestDialSelf(t *testing.T) {
s := NewSwarm(ctx, self, nil, nil) s := NewSwarm(ctx, self, nil, nil)
defer s.Close() defer s.Close()
ds := NewDialSync(s.dialWorker)
// this should fail // this should fail
_, err := ds.DialLock(ctx, self) _, err := s.dsync.DialLock(ctx, self)
if err != ErrDialToSelf { if err != ErrDialToSelf {
t.Fatal("expected error from self dial") t.Fatal("expected error from self dial")
} }
// do it twice to make sure we get a new active dial object that fails again // do it twice to make sure we get a new active dial object that fails again
_, err = ds.DialLock(ctx, self) _, err = s.dsync.DialLock(ctx, self)
if err != ErrDialToSelf { if err != ErrDialToSelf {
t.Fatal("expected error from self dial") t.Fatal("expected error from self dial")
} }
......
...@@ -121,7 +121,7 @@ func NewSwarm(ctx context.Context, local peer.ID, peers peerstore.Peerstore, bwc ...@@ -121,7 +121,7 @@ func NewSwarm(ctx context.Context, local peer.ID, peers peerstore.Peerstore, bwc
} }
} }
s.dsync = NewDialSync(s.dialWorker) s.dsync = newDialSync(s.dialWorker)
s.limiter = newDialLimiter(s.dialAddr, s.IsFdConsumingAddr) s.limiter = newDialLimiter(s.dialAddr, s.IsFdConsumingAddr)
s.proc = goprocessctx.WithContext(ctx) s.proc = goprocessctx.WithContext(ctx)
s.ctx = goprocessctx.OnClosingContext(s.proc) s.ctx = goprocessctx.OnClosingContext(s.proc)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment