Skip to content

Commit

Permalink
fix #44
Browse files Browse the repository at this point in the history
  • Loading branch information
firefart committed Feb 2, 2024
1 parent f52d3d5 commit c0c3dd5
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 58 deletions.
30 changes: 30 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/go
{
"name": "Go",
"image": "mcr.microsoft.com/devcontainers/go",
"features": {
"ghcr.io/guiyomh/features/golangci-lint:0": {},
"ghcr.io/devcontainers-contrib/features/go-task:1": {}
},
"postCreateCommand": "go mod download",
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "go version",
// Configure tool-specific properties.
"customizations": {
"vscode": {
"extensions": [
"golang.go",
"shardulm94.trailing-spaces",
"IBM.output-colorizer",
"task.vscode-task",
"github.vscode-github-actions",
"redhat.vscode-yaml"
]
}
}
}
9 changes: 6 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ jobs:
run: |
go get -v -t -d ./...
- name: Build
run: make build
- name: Build linux
run: task linux

- name: Build windows
run: task windows

- name: Test
run: make test
run: task test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ stunner
*.sh
*.txt
*.tar.gz
*.exe
release/
dist/
.env/
Expand Down
42 changes: 0 additions & 42 deletions Makefile

This file was deleted.

64 changes: 64 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
version: "3"

vars:
PROGRAM: stunner

tasks:
update:
cmds:
- go get -u
- go mod tidy -v

build:
aliases: [default]
cmds:
- go fmt ./...
- go vet ./...
- go build -o {{.OUTPUT_FILE | default .PROGRAM}}
env:
CGO_ENABLED: 0

linux:
cmds:
- task: build
env:
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64

windows:
cmds:
- task: build
vars:
OUTPUT_FILE: "{{.PROGRAM}}.exe"
env:
CGO_ENABLED: 0
GOOS: windows
GOARCH: amd64

test:
env:
CGO_ENABLED: 1 # required by -race
cmds:
- go test -race -cover ./...

lint:
cmds:
- golangci-lint run ./... --timeout=30m
- go mod tidy

lint-update:
cmds:
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b {{ .GOPATH }}/bin
- golangci-lint --version
vars:
GOPATH:
sh: go env GOPATH

tag:
cmds:
- git tag -a "${TAG}" -m "${TAG}"
- git push origin "${TAG}"
preconditions:
- sh: '[[ -n "${TAG}" ]]'
msg: "Please set the TAG environment variable"
37 changes: 24 additions & 13 deletions internal/helpers_turntcp.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package internal

import (
"crypto/tls"
"fmt"
"net"
"net/netip"
Expand All @@ -16,19 +17,24 @@ import (
// ConnectionBind
//
// it returns the controlConnection, the dataConnection and an error
func SetupTurnTCPConnection(logger DebugLogger, turnServer string, useTLS bool, timeout time.Duration, targetHost netip.Addr, targetPort uint16, username, password string) (*net.TCPConn, *net.TCPConn, error) {
func SetupTurnTCPConnection(logger DebugLogger, turnServer string, useTLS bool, timeout time.Duration, targetHost netip.Addr, targetPort uint16, username, password string) (net.Conn, net.Conn, error) {
// protocol needs to be tcp
controlConnectionRaw, err := Connect("tcp", turnServer, useTLS, timeout)
if err != nil {
return nil, nil, fmt.Errorf("error on establishing control connection: %w", err)
}

controlConnection, ok := controlConnectionRaw.(*net.TCPConn)
if !ok {
return nil, nil, fmt.Errorf("could not cast control connection to TCPConn")
}
if err := controlConnection.SetKeepAlive(true); err != nil {
return nil, nil, fmt.Errorf("could not set KeepAlive on control connection: %w", err)
var controlConnection net.Conn
switch t := controlConnectionRaw.(type) {
case *net.TCPConn:
if err := t.SetKeepAlive(true); err != nil {
return nil, nil, fmt.Errorf("could not set KeepAlive on control connection: %w", err)
}
controlConnection = t
case *tls.Conn:
controlConnection = t
default:
return nil, nil, fmt.Errorf("could not determine control connection type (%T)", t)
}

logger.Debugf("opened turn tcp control connection from %s to %s", controlConnection.LocalAddr().String(), controlConnection.RemoteAddr().String())
Expand Down Expand Up @@ -78,12 +84,17 @@ func SetupTurnTCPConnection(logger DebugLogger, turnServer string, useTLS bool,
return nil, nil, fmt.Errorf("error on establishing data connection: %w", err)
}

dataConnection, ok := dataConnectionRaw.(*net.TCPConn)
if !ok {
return nil, nil, fmt.Errorf("could not cast data connection to TCPConn")
}
if err := dataConnection.SetKeepAlive(true); err != nil {
return nil, nil, fmt.Errorf("could not set KeepAlive on data connection: %w", err)
var dataConnection net.Conn
switch t := dataConnectionRaw.(type) {
case *net.TCPConn:
if err := t.SetKeepAlive(true); err != nil {
return nil, nil, fmt.Errorf("could not set KeepAlive on data connection: %w", err)
}
dataConnection = t
case *tls.Conn:
dataConnection = t
default:
return nil, nil, fmt.Errorf("could not determine data connection type (%T)", t)
}

logger.Debugf("opened turn tcp data connection from %s to %s", dataConnection.LocalAddr().String(), dataConnection.RemoteAddr().String())
Expand Down

0 comments on commit c0c3dd5

Please sign in to comment.