Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mudler/edgevpn
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.27.4
Choose a base ref
...
head repository: mudler/edgevpn
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.28.0
Choose a head ref
  • 9 commits
  • 6 files changed
  • 2 contributors

Commits on Aug 26, 2024

  1. chore(dht): keep ring of randezvous points

    Signed-off-by: mudler <mudler@localai.io>
    mudler committed Aug 26, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    vmishenev Vadim Mishenev
    Copy the full SHA
    f60e426 View commit details
  2. Serial

    mudler committed Aug 26, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    vmishenev Vadim Mishenev
    Copy the full SHA
    8da3ded View commit details

Commits on Aug 27, 2024

  1. Avoid deadlocks

    Signed-off-by: mudler <mudler@localai.io>
    mudler committed Aug 27, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    vmishenev Vadim Mishenev
    Copy the full SHA
    0d7c447 View commit details
  2. Small changes

    mudler committed Aug 27, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    vmishenev Vadim Mishenev
    Copy the full SHA
    314f9bd View commit details
  3. Have a 2 min timeout for connecting to the nodes

    Signed-off-by: mudler <mudler@localai.io>
    mudler committed Aug 27, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    vmishenev Vadim Mishenev
    Copy the full SHA
    556ff98 View commit details
  4. Display error when failed to connect

    Signed-off-by: mudler <mudler@localai.io>
    mudler committed Aug 27, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    vmishenev Vadim Mishenev
    Copy the full SHA
    31ad9b5 View commit details
  5. Revert "fix(deps): update module github.com/libp2p/go-libp2p-kad-dht …

    …to v0.26.1 (#552)"
    
    This reverts commit e5891f2.
    mudler committed Aug 27, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    vmishenev Vadim Mishenev
    Copy the full SHA
    d068d5d View commit details
  6. Revert "fix(deps): update module github.com/libp2p/go-libp2p-pubsub t…

    …o v0.12.0 (#543)"
    
    This reverts commit 0760178.
    mudler committed Aug 27, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    vmishenev Vadim Mishenev
    Copy the full SHA
    81bdd76 View commit details
  7. Merge pull request #555 from mudler/randezvous_ring

    fix(dht): keep ring of rendezvous points
    mudler authored Aug 27, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    vmishenev Vadim Mishenev
    Copy the full SHA
    bd33f7c View commit details
Showing with 180 additions and 133 deletions.
  1. +34 −36 go.mod
  2. +0 −69 go.sum
  3. +52 −28 pkg/discovery/dht.go
  4. +26 −0 pkg/discovery/discovery_suite_test.go
  5. +20 −0 pkg/discovery/ring.go
  6. +48 −0 pkg/discovery/ring_test.go
70 changes: 34 additions & 36 deletions go.mod
Original file line number Diff line number Diff line change
@@ -12,14 +12,14 @@ require (
github.com/cenkalti/backoff/v4 v4.3.0
github.com/creachadair/otp v0.4.2
github.com/google/gopacket v1.1.19
github.com/hashicorp/golang-lru v1.0.2
github.com/hashicorp/golang-lru v0.5.4
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/ipfs/go-log v1.0.5
github.com/ipfs/go-log/v2 v2.5.1
github.com/labstack/echo/v4 v4.12.0
github.com/libp2p/go-libp2p v0.36.2
github.com/libp2p/go-libp2p-kad-dht v0.26.1
github.com/libp2p/go-libp2p-pubsub v0.12.0
github.com/libp2p/go-libp2p v0.35.4
github.com/libp2p/go-libp2p-kad-dht v0.25.2
github.com/libp2p/go-libp2p-pubsub v0.11.0
github.com/miekg/dns v1.1.62
github.com/mudler/go-processmanager v0.0.0-20230818213616-f204007f963c
github.com/mudler/water v0.0.0-20221010214108-8c7313014ce0
@@ -44,15 +44,15 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/elastic/gosigar v0.14.3 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/flynn/noise v1.1.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/go-logr/logr v1.4.2 // indirect
@@ -64,22 +64,22 @@ require (
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/ipfs/boxo v0.21.0 // indirect
github.com/ipfs/boxo v0.10.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
github.com/ipld/go-ipld-prime v0.21.0 // indirect
github.com/ipld/go-ipld-prime v0.20.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/koron/go-ssdp v0.0.4 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
@@ -88,7 +88,7 @@ require (
github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect
github.com/libp2p/go-libp2p-kbucket v0.6.3 // indirect
github.com/libp2p/go-libp2p-record v0.2.0 // indirect
github.com/libp2p/go-libp2p-routing-helpers v0.7.4 // indirect
github.com/libp2p/go-libp2p-routing-helpers v0.7.2 // indirect
github.com/libp2p/go-msgio v0.3.0 // indirect
github.com/libp2p/go-nat v0.2.0 // indirect
github.com/libp2p/go-netroute v0.2.1 // indirect
@@ -114,35 +114,34 @@ require (
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-multistream v0.5.0 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/runtime-spec v1.2.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pion/datachannel v1.5.8 // indirect
github.com/pion/dtls/v2 v2.2.12 // indirect
github.com/pion/ice/v2 v2.3.34 // indirect
github.com/pion/interceptor v0.1.30 // indirect
github.com/pion/datachannel v1.5.6 // indirect
github.com/pion/dtls/v2 v2.2.11 // indirect
github.com/pion/ice/v2 v2.3.25 // indirect
github.com/pion/interceptor v0.1.29 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/mdns v0.0.12 // indirect
github.com/pion/randutil v0.1.0 // indirect
github.com/pion/rtcp v1.2.14 // indirect
github.com/pion/rtp v1.8.9 // indirect
github.com/pion/sctp v1.8.33 // indirect
github.com/pion/rtp v1.8.6 // indirect
github.com/pion/sctp v1.8.16 // indirect
github.com/pion/sdp/v3 v3.0.9 // indirect
github.com/pion/srtp/v2 v2.0.20 // indirect
github.com/pion/srtp/v2 v2.0.18 // indirect
github.com/pion/stun v0.6.1 // indirect
github.com/pion/transport/v2 v2.2.10 // indirect
github.com/pion/transport/v2 v2.2.5 // indirect
github.com/pion/turn/v2 v2.1.6 // indirect
github.com/pion/webrtc/v3 v3.3.0 // indirect
github.com/pion/webrtc/v3 v3.2.40 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_golang v1.20.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/quic-go v0.46.0 // indirect
github.com/quic-go/quic-go v0.44.0 // indirect
github.com/quic-go/webtransport-go v0.8.0 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
@@ -159,28 +158,27 @@ require (
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/wlynxg/anet v0.0.4 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
go.opentelemetry.io/otel/trace v1.27.0 // indirect
go.uber.org/dig v1.18.0 // indirect
go.uber.org/fx v1.22.2 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.uber.org/dig v1.17.1 // indirect
go.uber.org/fx v1.22.1 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
golang.zx2c4.com/wireguard v0.0.0-20220703234212-c31a7b1ab478 // indirect
gonum.org/v1/gonum v0.15.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
lukechampine.com/blake3 v1.3.0 // indirect
gonum.org/v1/gonum v0.13.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
)

replace github.com/elastic/gosigar => github.com/mudler/gosigar v0.14.3-0.20220502202347-34be910bdaaf
69 changes: 0 additions & 69 deletions go.sum

Large diffs are not rendered by default.

80 changes: 52 additions & 28 deletions pkg/discovery/dht.go
Original file line number Diff line number Diff line change
@@ -38,14 +38,14 @@ type DHT struct {
KeyLength int
RendezvousString string
BootstrapPeers AddrList
latestRendezvous string
rendezvousHistory Ring
RefreshDiscoveryTime time.Duration
*dht.IpfsDHT
dhtOptions []dht.Option
}

func NewDHT(d ...dht.Option) *DHT {
return &DHT{dhtOptions: d}
return &DHT{dhtOptions: d, rendezvousHistory: Ring{Length: 2}}
}

func (d *DHT) Option(ctx context.Context) func(c *libp2p.Config) error {
@@ -57,9 +57,7 @@ func (d *DHT) Option(ctx context.Context) func(c *libp2p.Config) error {
func (d *DHT) Rendezvous() string {
if d.OTPKey != "" {
totp := internalCrypto.TOTP(sha256.New, d.KeyLength, d.OTPInterval, d.OTPKey)

rv := internalCrypto.MD5(totp)
d.latestRendezvous = rv
return rv
}
return d.RendezvousString
@@ -82,6 +80,19 @@ func (d *DHT) startDHT(ctx context.Context, h host.Host) (*dht.IpfsDHT, error) {
return d.IpfsDHT, nil
}

func (d *DHT) announceRendezvous(c log.StandardLogger, ctx context.Context, host host.Host, kademliaDHT *dht.IpfsDHT) {
d.bootstrapPeers(c, ctx, host)
rv := d.Rendezvous()
d.rendezvousHistory.Add(rv)

c.Debugf("The following rendezvous points are being used: %+v", d.rendezvousHistory.Data)
for _, r := range d.rendezvousHistory.Data {
c.Debugf("Announcing with rendezvous: %s", r)
d.announceAndConnect(c, ctx, kademliaDHT, host, r)
}
c.Debug("Announcing to rendezvous done")
}

func (d *DHT) Run(c log.StandardLogger, ctx context.Context, host host.Host) error {
if d.KeyLength == 0 {
d.KeyLength = 12
@@ -106,33 +117,42 @@ func (d *DHT) Run(c log.StandardLogger, ctx context.Context, host host.Host) err
return err
}

connect := func() {
d.bootstrapPeers(c, ctx, host)
if d.latestRendezvous != "" {
c.Debugf("Announcing with old rendezvous: %s", d.latestRendezvous)
d.announceAndConnect(c, ctx, kademliaDHT, host, d.latestRendezvous)
}
go d.runBackground(c, ctx, host, kademliaDHT)

rv := d.Rendezvous()
c.Debugf("Announcing with current rendezvous: %s", d.latestRendezvous)
d.announceAndConnect(c, ctx, kademliaDHT, host, rv)
}
return nil
}

func (d *DHT) runBackground(c log.StandardLogger, ctx context.Context, host host.Host, kademliaDHT *dht.IpfsDHT) {
d.announceRendezvous(c, ctx, host, kademliaDHT)
t := utils.NewBackoffTicker(utils.BackoffMaxInterval(d.RefreshDiscoveryTime))
defer t.Stop()
for {
select {
case <-t.C:
// We announce ourselves to the rendezvous point for all the peers.
// We have a safeguard of 1 hour to avoid blocking the main loop
// in case of network issues.
// The TTL of DHT is by default no longer than 3 hours, so we should
// be safe by having an entry less than that.
safeTimeout, cancel := context.WithTimeout(ctx, time.Hour)

endChan := make(chan struct{})
go func() {
d.announceRendezvous(c, safeTimeout, host, kademliaDHT)
endChan <- struct{}{}
}()

go func() {
go connect()
t := utils.NewBackoffTicker(utils.BackoffMaxInterval(d.RefreshDiscoveryTime))
defer t.Stop()
for {
select {
case <-t.C:
go connect()
case <-ctx.Done():
return
case <-endChan:
cancel()
case <-safeTimeout.Done():
c.Error("Timeout while announcing rendezvous")
cancel()
}
case <-ctx.Done():
return
}
}()

return nil
}
}

func (d *DHT) bootstrapPeers(c log.StandardLogger, ctx context.Context, host host.Host) {
@@ -223,8 +243,10 @@ func (d *DHT) announceAndConnect(l log.StandardLogger, ctx context.Context, kade

if host.Network().Connectedness(p.ID) != network.Connected {
l.Debug("Found peer:", p)
if err := host.Connect(ctx, p); err != nil {
l.Debug("Failed connecting to", p)
timeoutCtx, cancel := context.WithTimeout(ctx, time.Second*120)
defer cancel()
if err := host.Connect(timeoutCtx, p); err != nil {
l.Debugf("Failed connecting to '%s', error: '%s'", p, err.Error())
} else {
l.Debug("Connected to:", p)
}
@@ -233,5 +255,7 @@ func (d *DHT) announceAndConnect(l log.StandardLogger, ctx context.Context, kade
}
}

l.Debug("Finished searching for peers.")

return nil
}
26 changes: 26 additions & 0 deletions pkg/discovery/discovery_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright © 2021-2024 Ettore Di Giacinto <mudler@mocaccino.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package discovery_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestDiscovery(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Discovery Suite")
}
20 changes: 20 additions & 0 deletions pkg/discovery/ring.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package discovery

type Ring struct {
Data []string
Length int
}

func (r *Ring) Add(s string) {
if len(r.Data) > 0 {
// Avoid duplicates of the last item
if r.Data[len(r.Data)-1] == s {
return
}
}

if len(r.Data)+1 > r.Length {
r.Data = r.Data[1:]
}
r.Data = append(r.Data, s)
}
48 changes: 48 additions & 0 deletions pkg/discovery/ring_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright © 2021-2022 Ettore Di Giacinto <mudler@mocaccino.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package discovery_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

. "github.com/mudler/edgevpn/pkg/discovery"
)

var _ = Describe("String utilities", func() {
Context("Ring", func() {
It("adds elements to the ring (3)", func() {
R := Ring{Length: 3}
R.Add("a")
R.Add("b")
R.Add("c")
Expect(R.Data).To(Equal([]string{"a", "b", "c"}))
R.Add("d")
Expect(R.Data).To(Equal([]string{"b", "c", "d"}))
R.Add("d")
Expect(R.Data).To(Equal([]string{"b", "c", "d"}))
})
It("adds elements to the ring (2)", func() {
R := Ring{Length: 2}
R.Add("a")
R.Add("b")
R.Add("c")
Expect(R.Data).To(Equal([]string{"b", "c"}))
R.Add("d")
Expect(R.Data).To(Equal([]string{"c", "d"}))
R.Add("d")
Expect(R.Data).To(Equal([]string{"c", "d"}))
})
})
})