multiformats / go-multistream

an implementation of the multistream protocol in go
MIT License
41 stars 27 forks source link

Possible incompatibility with different versions of simopen protocol #69

Closed mcrakhman closed 3 years ago

mcrakhman commented 3 years ago

Recently we updated our server node to use go-ipfs 0.9.0-rc1, our client nodes are using github.com/libp2p/go-libp2p v0.13.1-0.20210426194311-0b6144a02fdf.

Immediately after this update we started getting a lot of these errors: {"level":"warn","ts":"2021-05-31T22:33:38.147+0300","logger":"...","caller":"...","msg":.. failed to negotiate security protocol: unexpected response: /libp2p/simultaneous-connect"}

By looking inside the method SelectWithSimopenOrFail I found out some differences in the code which we are using in the server node:

         switch tok {
    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)
    }

and the client node

         switch tok {
    case "iamclient":
        // 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)
    }

So looks like the client receives unexpected string which is /libp2p/simultaneous-connect instead of iamclient, that's why we get these errors. What should we do then? Should we just update all our clients to the new version of libp2p (0.14.0)?

Stebalien commented 3 years ago

Yes. Well, update to 0.14.1 (just released; 0.14.0 had a yamux compatibility issue).

We had assumed that nobody was using that version of go-multistream because it had never been included in a released version of go-libp2p. Unfortunately, it was included in a released version of this library before the spec was finalized...

Note: this should only happen when you have a TCP simultanious open. That is, both ends connect to each other at the exact same time.

Does that solve your issue?

mcrakhman commented 3 years ago

Thanks for the prompt reply @Stebalien!

It turned out that it is hard to us to update clients to the new version. Is my understanding correct that just updating the server to 0.14.1 will not solve the problem (because we still have different messages: iamclient vs /libp2p/simultaneous-connect)?

Or am I missing something and we can just update the server to the new version? Otherwise we would have to revert back our server update.

Stebalien commented 3 years ago

Yes, you'd have to update the clients, not just the server.

Note: you should only get this error if both sides decide to connect to each other at the exact same time. This error really shouldn't be all that common.

aschmahmann commented 3 years ago

Closing, for tracking purposes, since the current behavior is intended. However, if you're still running into problems here feel free to continue asking on this issue.