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: . 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/dialer_test.go b/fastdialer/dialer_test.go index fef32b1..964b399 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) { @@ -52,24 +53,25 @@ func testDialer(t *testing.T, options Options) { fd.Close() } +// nolint 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 +81,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 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