Browse Source

webtransport: add and check the ?type=noise URL parameter (#1749)

pull/1758/head
Marten Seemann 2 years ago
committed by GitHub
parent
commit
5ab6d3fd1d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      p2p/transport/webtransport/listener.go
  2. 2
      p2p/transport/webtransport/transport.go

6
p2p/transport/webtransport/listener.go

@ -108,6 +108,11 @@ func newListener(laddr ma.Multiaddr, transport tpt.Transport, noise *noise.Trans
}
func (l *listener) httpHandler(w http.ResponseWriter, r *http.Request) {
typ, ok := r.URL.Query()["type"]
if !ok || len(typ) != 1 || typ[0] != "noise" {
w.WriteHeader(http.StatusBadRequest)
return
}
remoteMultiaddr, err := stringToWebtransportMultiaddr(r.RemoteAddr)
if err != nil {
// This should never happen.
@ -127,7 +132,6 @@ func (l *listener) httpHandler(w http.ResponseWriter, r *http.Request) {
return
}
// TODO: check ?type=multistream URL param
sess, err := l.server.Upgrade(w, r)
if err != nil {
log.Debugw("upgrade failed", "error", err)

2
p2p/transport/webtransport/transport.go

@ -150,7 +150,7 @@ func (t *transport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (tp
}
func (t *transport) dial(ctx context.Context, addr string, certHashes []multihash.DecodedMultihash) (*webtransport.Session, error) {
url := fmt.Sprintf("https://%s%s", addr, webtransportHTTPEndpoint)
url := fmt.Sprintf("https://%s%s?type=noise", addr, webtransportHTTPEndpoint)
var tlsConf *tls.Config
if t.tlsClientConf != nil {
tlsConf = t.tlsClientConf.Clone()

Loading…
Cancel
Save