-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor net code to use transports, in rough accordance with libp2p #1937
Conversation
@jbenet one question I still have is how to wire timeouts into the Dialer through this interface. |
@whyrusleeping probably extend it to have the same vars? not sure. |
@jbenet but its an interface... Its going to have to be one of:
or
|
type Transport interface {
Dialer(la ma.Multiaddr, opts ...DialOpts) (Dialer, error)
}
type DialOpts func(*Transport) error
func SetTimeout(t time.Duration) DialOpts {
return func(tr *Transport) error {
// setup timeout on tr
}
} seems more flexible to me. |
@cryptix i'd like to be able to use the functional options, but in this case its non-trivial (and more trouble than its worth). Each implementation of a transport dialer may want different options, and have different ways of setting them, so we cant nicely make it a method on the interface. |
Couldn't you type assert to other interface in func SetTimeout(t time.Duration) DialOpts {
return func(tr *Transport) error {
switch v := tr.(type) {
case ma.Timeouter:
_ = v.SetTimeout(t)
case net.Dialer:
d := net.Dialer{Timeout: timeout}
tr.UseDialer(d)
}
}
} |
@whyrusleeping #1937 (comment) Can't it be one of the opts when you instantiate the Transport for the first time? |
@diasdavid yeah... it could be. but then that makes it pretty difficult to change the settings later on if needed. |
return newMeteredConn(c, bwc.LogRecvMessage, bwc.LogSentMessage) | ||
} | ||
|
||
func newMeteredConn(base manet.Conn, rcb metrics.MeterCallback, scb metrics.MeterCallback) manet.Conn { | ||
func newMeteredConn(base transport.Conn, rcb metrics.MeterCallback, scb metrics.MeterCallback) transport.Conn { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is MeteredConn a 'Connection Upgrade' that dumps bandwidth metrics? This is really a great idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeap!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want it the js stuff! :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diasdavid just another transport :)
2bb574c
to
79de2a5
Compare
Once we merge this, rebase 0.4.0 and extract libp2p, i'm going to grab most of the actual 'networking' code from multiaddr-net and put it in the transport lib, leaving all of the multiaddr parsing/handling code there. |
|
||
type Transport interface { | ||
Dialer(laddr ma.Multiaddr, opts ...DialOpt) (Dialer, error) | ||
Listener(laddr ma.Multiaddr) (Listener, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just Listen
to match go? not sure. we can always change it later.
@whyrusleeping this LGTM! great, great changeset. Really happy with how this interface turned out. only major thing to fix is:
minor:
|
99010f0
to
991c165
Compare
alright, we no longer fail out on swarm setup unless all listens fail. |
1682dc3
to
6885955
Compare
22c41ea
to
efd0753
Compare
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
And other assorted PR feedback License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
efd0753
to
94647ed
Compare
refactor net code to use transports, in rough accordance with libp2p
refactor as discussed with @jbenet. (with a couple extra methods on the interfaces)
This has the nice effect of removing go-multiaddr-net imports from a lot of places.
License: MIT
Signed-off-by: Jeromy jeromyj@gmail.com