Skip to content

Commit

Permalink
webtransport: add and check the ?type=noise URL parameter (#1749)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann authored Sep 15, 2022
1 parent a4e45c2 commit 5ab6d3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion p2p/transport/webtransport/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion p2p/transport/webtransport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5ab6d3f

Please sign in to comment.