dendrite/cmd/dendrite-demo-pinecone/conn/client.go
dependabot[bot] 285d065e02
Bump nhooyr.io/websocket from 1.8.7 to 1.8.17 (#3456)
Bumps [nhooyr.io/websocket](https://github.com/nhooyr/websocket-old)
from 1.8.7 to 1.8.17.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/nhooyr/websocket-old/releases">nhooyr.io/websocket's
releases</a>.</em></p>
<blockquote>
<h2>v1.8.17</h2>
<ul>
<li>This library is now deprecated. Please do not use this library any
longer at the <code>nhooyr.io/websocket</code> import path. It will not
receive any further updates.
Coder is now maintaining it at <a
href="https://github.com/coder/websocket">https://github.com/coder/websocket</a>
under the <code>github.com/coder/websocket</code> import path.</li>
</ul>
<h2>v1.8.16</h2>
<ul>
<li>Please do not use this library any longer at the
<code>nhooyr.io/websocket</code> import path as it is deprecated. It
will not receive any maintenance updates.
Coder is maintaining it now at <a
href="https://github.com/coder/websocket">https://github.com/coder/websocket</a>
under the <code>github.com/coder/websocket</code> import path.</li>
</ul>
<h2>v1.8.15</h2>
<ul>
<li>Please do not use this library any longer at the
<code>nhooyr.io/websocket</code> import path as it is deprecated. It
will not receive any maintenance updates.
Coder is maintaining it now at <a
href="https://github.com/coder/websocket">https://github.com/coder/websocket</a>
under the <code>github.com/coder/websocket</code> import path.</li>
</ul>
<h2>v1.8.14</h2>
<ul>
<li>Please do not use this library any longer at the
<code>nhooyr.io/websocket</code> import path as it is deprecated. It
will not receive any maintenance updates.
Coder is maintaining it now at <a
href="https://github.com/coder/websocket">https://github.com/coder/websocket</a>
under the <code>github.com/coder/websocket</code> import path.</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li>See full diff in <a
href="https://github.com/nhooyr/websocket-old/commits/v1.8.17">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=nhooyr.io/websocket&package-manager=go_modules&previous-version=1.8.7&new-version=1.8.17)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Till Faelligen <2353100+S7evinK@users.noreply.github.com>
2024-12-18 08:01:41 +01:00

99 lines
2.5 KiB
Go

// Copyright 2024 New Vector Ltd.
// Copyright 2022 The Matrix.org Foundation C.I.C.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
package conn
import (
"context"
"fmt"
"net"
"net/http"
"strings"
"github.com/coder/websocket"
"github.com/element-hq/dendrite/setup/config"
"github.com/matrix-org/gomatrixserverlib/fclient"
pineconeRouter "github.com/matrix-org/pinecone/router"
pineconeSessions "github.com/matrix-org/pinecone/sessions"
)
func ConnectToPeer(pRouter *pineconeRouter.Router, peer string) error {
var parent net.Conn
if strings.HasPrefix(peer, "ws://") || strings.HasPrefix(peer, "wss://") {
ctx := context.Background()
c, _, err := websocket.Dial(ctx, peer, nil)
if err != nil {
return fmt.Errorf("websocket.DefaultDialer.Dial: %w", err)
}
parent = websocket.NetConn(ctx, c, websocket.MessageBinary)
} else {
var err error
parent, err = net.Dial("tcp", peer)
if err != nil {
return fmt.Errorf("net.Dial: %w", err)
}
}
if parent == nil {
return fmt.Errorf("failed to wrap connection")
}
_, err := pRouter.Connect(
parent,
pineconeRouter.ConnectionZone("static"),
pineconeRouter.ConnectionPeerType(pineconeRouter.PeerTypeRemote),
pineconeRouter.ConnectionURI(peer),
)
return err
}
type RoundTripper struct {
inner *http.Transport
}
func (y *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
req.URL.Scheme = "http"
return y.inner.RoundTrip(req)
}
func createTransport(s *pineconeSessions.Sessions) *http.Transport {
proto := s.Protocol("matrix")
tr := &http.Transport{
DisableKeepAlives: false,
Dial: proto.Dial,
DialContext: proto.DialContext,
DialTLS: proto.DialTLS,
DialTLSContext: proto.DialTLSContext,
}
tr.RegisterProtocol(
"matrix", &RoundTripper{
inner: &http.Transport{
DisableKeepAlives: false,
Dial: proto.Dial,
DialContext: proto.DialContext,
DialTLS: proto.DialTLS,
DialTLSContext: proto.DialTLSContext,
},
},
)
return tr
}
func CreateClient(
s *pineconeSessions.Sessions,
) *fclient.Client {
return fclient.NewClient(
fclient.WithTransport(createTransport(s)),
)
}
func CreateFederationClient(
cfg *config.Dendrite, s *pineconeSessions.Sessions,
) fclient.FederationClient {
return fclient.NewFederationClient(
cfg.Global.SigningIdentities(),
fclient.WithTransport(createTransport(s)),
)
}