From 856aa05936105b5d8f4f273e7720c0415691dc6d Mon Sep 17 00:00:00 2001 From: mzack Date: Wed, 22 Jun 2022 14:29:47 +0200 Subject: [PATCH 1/4] Adding on dial callback --- fastdialer/dialer.go | 3 +++ fastdialer/options.go | 1 + 2 files changed, 4 insertions(+) diff --git a/fastdialer/dialer.go b/fastdialer/dialer.go index 59d2c11..8c90672 100644 --- a/fastdialer/dialer.go +++ b/fastdialer/dialer.go @@ -235,6 +235,9 @@ func (d *Dialer) dial(ctx context.Context, network, address string, shouldUseTLS return nil, setErr } } + if d.options.OnDialCallback != nil { + d.options.OnDialCallback(hostname, ip) + } if d.options.WithTLSData && shouldUseTLS { if connTLS, ok := conn.(*tls.Conn); ok { var data bytes.Buffer diff --git a/fastdialer/options.go b/fastdialer/options.go index cd6c57f..320518c 100644 --- a/fastdialer/options.go +++ b/fastdialer/options.go @@ -47,6 +47,7 @@ type Options struct { Dialer *net.Dialer WithZTLS bool SNIName string + OnDialCallback func(hostname, IP string) } // DefaultOptions of the cache From e5c45634bc14d29b32df8b75046bd060b949617f Mon Sep 17 00:00:00 2001 From: mzack Date: Wed, 22 Jun 2022 14:33:12 +0200 Subject: [PATCH 2/4] updating gh actions --- .github/workflows/build-test.yml | 26 ++++++++++++++++++++++++++ .github/workflows/codeql-analysis.yml | 9 ++++----- .github/workflows/lint-test.yml | 10 +++++++--- 3 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/build-test.yml diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 0000000..2ee7a85 --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,26 @@ +name: 🔨 Build Test +on: + push: + pull_request: + workflow_dispatch: + + +jobs: + build: + name: Test Builds + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.18 + + - name: Check out code + uses: actions/checkout@v3 + + - name: Test + run: go test ./... + + # Todo: create example folder + # - name: Build + # run: go build . \ No newline at end of file diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 792785b..9f533f8 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -2,7 +2,6 @@ name: 🚨 CodeQL Analysis on: workflow_dispatch: - push: pull_request: branches: - dev @@ -24,16 +23,16 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@v2 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 \ No newline at end of file + uses: github/codeql-action/analyze@v2 \ No newline at end of file diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml index 794d073..2059f5b 100644 --- a/.github/workflows/lint-test.yml +++ b/.github/workflows/lint-test.yml @@ -10,10 +10,14 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.18 - name: Run golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v3.2.0 with: version: latest args: --timeout 5m - working-directory: . \ No newline at end of file + working-directory: . From 07f739f0d4a3e8612dcc6b29b5768c6c7fdd44ec Mon Sep 17 00:00:00 2001 From: mzack Date: Wed, 22 Jun 2022 14:36:04 +0200 Subject: [PATCH 3/4] commenting out ipv6 --- fastdialer/dialer_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/fastdialer/dialer_test.go b/fastdialer/dialer_test.go index fef32b1..3b1fbbb 100644 --- a/fastdialer/dialer_test.go +++ b/fastdialer/dialer_test.go @@ -23,7 +23,8 @@ func TestDialer(t *testing.T) { options.CacheType = Hybrid options.CacheMemoryMaxItems = 100 testDialer(t, options) - testDialerIpv6(t, options) + + // testDialerIpv6(t, options) not supported by GitHub VMs } func testDialer(t *testing.T, options Options) { @@ -56,20 +57,20 @@ func testDialerIpv6(t *testing.T, options Options) { // disk based fd, err := NewDialer(options) if err != nil { - t.Errorf("couldn't create fastdialer instance: %s", err) + t.Fatalf("couldn't create fastdialer instance: %s", err) } // valid resolution + cache ctx := context.Background() conn, err := fd.Dial(ctx, "tcp", "ipv6.google.com:80") if err != nil || conn == nil { - t.Errorf("couldn't connect to target: %s", err) + t.Fatalf("couldn't connect to target: %s", err) } conn.Close() // retrieve cached data data, err := fd.GetDNSData("ipv6.google.com") if err != nil || data == nil { - t.Errorf("couldn't retrieve dns data: %s", err) + t.Fatalf("couldn't retrieve dns data: %s", err) } if len(data.AAAA) == 0 { t.Error("no AAAA results found") @@ -79,11 +80,11 @@ func testDialerIpv6(t *testing.T, options Options) { // this test passes, but will fail if the hard-coded ipv6 address changes // need to find a better way to test this /* - conn, err = fd.Dial(ctx, "tcp", "ipv6.google.com:80:[2607:f8b0:4006:807::200e]") - if err != nil || conn == nil { - t.Errorf("couldn't connect to target: %s", err) - } - conn.Close() + conn, err = fd.Dial(ctx, "tcp", "ipv6.google.com:80:[2607:f8b0:4006:807::200e]") + if err != nil || conn == nil { + t.Errorf("couldn't connect to target: %s", err) + } + conn.Close() */ // cleanup From 75f5afa1a3e56c4afd92839b9e1f7c828e1e78d2 Mon Sep 17 00:00:00 2001 From: mzack Date: Wed, 22 Jun 2022 14:37:35 +0200 Subject: [PATCH 4/4] lint ignore --- fastdialer/dialer_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/fastdialer/dialer_test.go b/fastdialer/dialer_test.go index 3b1fbbb..964b399 100644 --- a/fastdialer/dialer_test.go +++ b/fastdialer/dialer_test.go @@ -53,6 +53,7 @@ func testDialer(t *testing.T, options Options) { fd.Close() } +// nolint func testDialerIpv6(t *testing.T, options Options) { // disk based fd, err := NewDialer(options)