Skip to content
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

change the simultaneous open protocol to /libp2p/simultaneous-connect #66

Merged
merged 1 commit into from
May 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func SelectOneOf(protos []string, rwc io.ReadWriteCloser) (string, error) {
return selectProtosOrFail(protos[1:], rwc)
}

const simOpenProtocol = "/libp2p/simultaneous-connect"

// Performs protocol negotiation with the simultaneous open extension; the returned boolean
// indicator will be true if we should act as a server.
func SelectWithSimopenOrFail(protos []string, rwc io.ReadWriteCloser) (string, bool, error) {
Expand All @@ -86,7 +88,7 @@ func SelectWithSimopenOrFail(protos []string, rwc io.ReadWriteCloser) (string, b
werrCh := make(chan error, 1)
go func() {
var buf bytes.Buffer
if err := delitmWriteAll(&buf, []byte(ProtocolID), []byte("iamclient"), []byte(protos[0])); err != nil {
if err := delitmWriteAll(&buf, []byte(ProtocolID), []byte(simOpenProtocol), []byte(protos[0])); err != nil {
werrCh <- err
return
}
Expand All @@ -110,19 +112,16 @@ func SelectWithSimopenOrFail(protos []string, rwc io.ReadWriteCloser) (string, b
}

switch tok {
case "iamclient":
case simOpenProtocol:
// simultaneous open
return simOpen(protos, rwc)

case "na":
// client open
proto, err := clientOpen(protos, rwc)
if err != nil {
return "", false, err
}

return proto, false, nil

default:
return "", false, errors.New("unexpected response: " + tok)
}
Expand Down