Skip to content

Commit

Permalink
Adding on dial callback + Updating GitHub actions (#47)
Browse files Browse the repository at this point in the history
* Adding on dial callback

* updating gh actions

* commenting out ipv6

* lint ignore
  • Loading branch information
Mzack9999 committed Jul 1, 2022
1 parent ba02147 commit 4e4f6dc
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 17 deletions.
26 changes: 26 additions & 0 deletions .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 .
9 changes: 4 additions & 5 deletions .github/workflows/codeql-analysis.yml
Expand Up @@ -2,7 +2,6 @@ name: 🚨 CodeQL Analysis

on:
workflow_dispatch:
push:
pull_request:
branches:
- dev
Expand All @@ -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
uses: github/codeql-action/analyze@v2
10 changes: 7 additions & 3 deletions .github/workflows/lint-test.yml
Expand Up @@ -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: .
working-directory: .
3 changes: 3 additions & 0 deletions fastdialer/dialer.go
Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions fastdialer/dialer_test.go
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions fastdialer/options.go
Expand Up @@ -47,6 +47,7 @@ type Options struct {
Dialer *net.Dialer
WithZTLS bool
SNIName string
OnDialCallback func(hostname, IP string)
}

// DefaultOptions of the cache
Expand Down

0 comments on commit 4e4f6dc

Please sign in to comment.