]> Sergey Matveev's repositories - btrtrc.git/blobdiff - handshake.go
Drop support for go 1.20
[btrtrc.git] / handshake.go
index 83d322bf40a67de9cbd615306e5aef5cde8fac2e..b38a7086e83227003b7c5f7b5ef0af120dc76986 100644 (file)
@@ -27,6 +27,7 @@ func (r deadlineReader) Read(b []byte) (int, error) {
        return r.r.Read(b)
 }
 
+// Handles stream encryption for inbound connections.
 func handleEncryption(
        rw io.ReadWriter,
        skeys mse.SecretKeyIter,
@@ -38,12 +39,14 @@ func handleEncryption(
        cryptoMethod mse.CryptoMethod,
        err error,
 ) {
+       // Tries to start an unencrypted stream.
        if !policy.RequirePreferred || !policy.Preferred {
                var protocol [len(pp.Protocol)]byte
                _, err = io.ReadFull(rw, protocol[:])
                if err != nil {
                        return
                }
+               // Put the protocol back into the stream.
                rw = struct {
                        io.Reader
                        io.Writer
@@ -56,6 +59,7 @@ func handleEncryption(
                        return
                }
                if policy.RequirePreferred {
+                       // We are here because we require unencrypted connections.
                        err = fmt.Errorf("unexpected protocol string %q and header obfuscation disabled", protocol)
                        return
                }