host: add tests for protocol preferences in host

This commit is contained in:
Jeromy
2016-08-17 14:09:41 -07:00
committed by Jeromy Johnson
parent e51398525a
commit fc64ec9027
2 changed files with 171 additions and 5 deletions

View File

@@ -190,12 +190,21 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I
var lastErr error
for _, pid := range pids {
s, err := h.newStream(ctx, p, pid)
if err == nil {
h.setPreferredProtocol(p, pid)
return s, nil
if err != nil {
lastErr = err
log.Infof("NewStream to %s for %s failed: %s", p, pid, err)
continue
}
lastErr = err
log.Infof("NewStream to %s for %s failed: %s", p, pid, err)
_, err = s.Read(nil)
if err != nil {
lastErr = err
log.Infof("NewStream to %s for %s failed (on read): %s", p, pid, err)
continue
}
h.setPreferredProtocol(p, pid)
return s, nil
}
return nil, lastErr
@@ -248,6 +257,8 @@ func (h *BasicHost) newStream(ctx context.Context, p peer.ID, pid protocol.ID) (
return nil, err
}
s.SetProtocol(string(pid))
logStream := mstream.WrapStream(s, pid, h.bwc)
lzcon := msmux.NewMSSelect(logStream, string(pid))