Skip to content

Commit

Permalink
* make yaml list config supports single value without list format
Browse files Browse the repository at this point in the history
* rename dep/msquic to dep/_msquic for ignoring it
* upgrade quic-go to v0.40 from v0.35
* improvements
  • Loading branch information
vyloy committed Nov 3, 2023
1 parent 0a39183 commit b5f5601
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 214 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: '1.20'

- name: package-server
run: |-
Expand Down
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
url = https://git.mirror.iscas.ac.cn/ao-space/google-webrtc.git
branch = main
shallow = true
[submodule "dep/msquic"]
path = dep/msquic
[submodule "dep/_msquic"]
path = dep/_msquic
url = https://github.com/microsoft/msquic
97 changes: 50 additions & 47 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ export GOOS?=$(shell go env GOOS)
export GOARCH?=$(shell go env GOARCH)
export CC=$(TARGET)-gcc -w
export CXX=$(TARGET)-g++ -w
export CGO_CXXFLAGS=-I$(shell pwd)/dep/_google-webrtc/src \
-I$(shell pwd)/dep/_google-webrtc/src/third_party/abseil-cpp \
-I$(shell pwd)/dep/msquic/src/inc \
PWD=$(shell pwd)
export CGO_CXXFLAGS=-I$(PWD)/dep/_google-webrtc/src \
-I$(PWD)/dep/_google-webrtc/src/third_party/abseil-cpp \
-I$(PWD)/dep/_msquic/src/inc \
-std=c++17 -DWEBRTC_POSIX -DQUIC_API_ENABLE_PREVIEW_FEATURES
export CGO_LDFLAGS= $(shell pwd)/dep/_google-webrtc/src/out/release-$(TARGET)/obj/libwebrtc.a \
$(shell pwd)/dep/msquic/$(TARGET)/bin/Release/libmsquic.a \
export CGO_LDFLAGS= $(PWD)/dep/_google-webrtc/src/out/release-$(TARGET)/obj/libwebrtc.a \
$(PWD)/dep/_msquic/$(TARGET)/bin/Release/libmsquic.a \
-ldl -pthread
export CGO_ENABLED=1

Expand All @@ -78,7 +79,7 @@ gofumpt:

test: compile_webrtc compile_msquic
$(eval CGO_CXXFLAGS+=-O0 -g -ggdb)
go test -race -cover -count 1 ./bufio ./client ./config ./server ./test ./util
go test -race -cover -count 1 ./...

golangci-lint:
golangci-lint --version || go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
Expand All @@ -95,24 +96,24 @@ golangci-lint:
update_submodule:
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_google-webrtc
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/clog
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/googletest
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/openssl
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/openssl/boringssl
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/openssl3
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/openssl3/gost-engine
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/openssl/krb5
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/openssl3/gost-engine/libprov
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/openssl/pyca-cryptography
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/openssl3/krb5
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/openssl/wycheproof
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/openssl3/oqs-provider
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/openssl3/pyca-cryptography
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/openssl3/python-ecdsa
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/openssl3/tlsfuzzer
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/openssl3/tlslite-ng
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/msquic/submodules/openssl3/wycheproof
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/clog
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/googletest
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/openssl
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/openssl/boringssl
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/openssl3
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/openssl3/gost-engine
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/openssl/krb5
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/openssl3/gost-engine/libprov
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/openssl/pyca-cryptography
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/openssl3/krb5
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/openssl/wycheproof
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/openssl3/oqs-provider
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/openssl3/pyca-cryptography
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/openssl3/python-ecdsa
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/openssl3/tlsfuzzer
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/openssl3/tlslite-ng
git config --global --add safe.directory /go/src/github.com/isrc-cas/gt/dep/_msquic/submodules/openssl3/wycheproof
$(UPDATE_SUBMODULE_COMMAND)

docker_create_image: update_submodule
Expand All @@ -122,31 +123,31 @@ docker_build_linux_amd64: docker_build_linux_amd64_server docker_build_linux_amd
docker_release_linux_amd64: docker_release_linux_amd64_server docker_release_linux_amd64_client
docker_build_linux_amd64_client: docker_create_image
$(eval MAKE_ENV=TARGET=x86_64-linux-gnu GOOS=linux GOARCH=amd64 STATIC_LINK=$(STATIC_LINK) RACE_CHECK=$(RACE_CHECK) WITH_OFFICIAL_WEBRTC=$(WITH_OFFICIAL_WEBRTC))
docker run --rm -v $(shell pwd):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make build_client'
docker run --rm -v $(PWD):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make build_client'
docker_release_linux_amd64_client: docker_create_image
$(eval MAKE_ENV=TARGET=x86_64-linux-gnu GOOS=linux GOARCH=amd64 STATIC_LINK=$(STATIC_LINK) RACE_CHECK=$(RACE_CHECK) WITH_OFFICIAL_WEBRTC=$(WITH_OFFICIAL_WEBRTC))
docker run --rm -v $(shell pwd):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make release_client'
docker run --rm -v $(PWD):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make release_client'
docker_build_linux_amd64_server: docker_create_image
$(eval MAKE_ENV=TARGET=x86_64-linux-gnu GOOS=linux GOARCH=amd64 STATIC_LINK=$(STATIC_LINK) RACE_CHECK=$(RACE_CHECK) WITH_OFFICIAL_WEBRTC=$(WITH_OFFICIAL_WEBRTC))
docker run --rm -v $(shell pwd):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make build_server'
docker run --rm -v $(PWD):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make build_server'
docker_release_linux_amd64_server: docker_create_image
$(eval MAKE_ENV=TARGET=x86_64-linux-gnu GOOS=linux GOARCH=amd64 STATIC_LINK=$(STATIC_LINK) RACE_CHECK=$(RACE_CHECK) WITH_OFFICIAL_WEBRTC=$(WITH_OFFICIAL_WEBRTC))
docker run --rm -v $(shell pwd):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make release_server'
docker run --rm -v $(PWD):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make release_server'

docker_build_linux_arm64: docker_build_linux_arm64_server docker_build_linux_arm64_client
docker_release_linux_arm64: docker_release_linux_arm64_server docker_release_linux_arm64_client
docker_build_linux_arm64_client: docker_create_image
$(eval MAKE_ENV=TARGET=aarch64-linux-gnu GOOS=linux GOARCH=arm64 STATIC_LINK=$(STATIC_LINK) RACE_CHECK=$(RACE_CHECK) WITH_OFFICIAL_WEBRTC=$(WITH_OFFICIAL_WEBRTC))
docker run --rm -v $(shell pwd):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make build_client'
docker run --rm -v $(PWD):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make build_client'
docker_release_linux_arm64_client: docker_create_image
$(eval MAKE_ENV=TARGET=aarch64-linux-gnu GOOS=linux GOARCH=arm64 STATIC_LINK=$(STATIC_LINK) RACE_CHECK=$(RACE_CHECK) WITH_OFFICIAL_WEBRTC=$(WITH_OFFICIAL_WEBRTC))
docker run --rm -v $(shell pwd):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make release_client'
docker run --rm -v $(PWD):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make release_client'
docker_build_linux_arm64_server: docker_create_image
$(eval MAKE_ENV=TARGET=aarch64-linux-gnu GOOS=linux GOARCH=arm64 STATIC_LINK=$(STATIC_LINK) RACE_CHECK=$(RACE_CHECK) WITH_OFFICIAL_WEBRTC=$(WITH_OFFICIAL_WEBRTC))
docker run --rm -v $(shell pwd):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make build_server'
docker run --rm -v $(PWD):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make build_server'
docker_release_linux_arm64_server: docker_create_image
$(eval MAKE_ENV=TARGET=aarch64-linux-gnu GOOS=linux GOARCH=arm64 STATIC_LINK=$(STATIC_LINK) RACE_CHECK=$(RACE_CHECK) WITH_OFFICIAL_WEBRTC=$(WITH_OFFICIAL_WEBRTC))
docker run --rm -v $(shell pwd):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make release_server'
docker run --rm -v $(PWD):/go/src/github.com/isrc-cas/gt -w /go/src/github.com/isrc-cas/gt gtbuild:v1 sh -c '$(MAKE_ENV) make release_server'

build: build_server build_client
release: release_server release_client
Expand Down Expand Up @@ -243,24 +244,26 @@ compile_webrtc: check_webrtc_dependencies update_submodule
use_lld=false \
use_rtti=true \
use_sysroot=false"
sed -i 's| [^ ]*gcc | $(CC) |g' ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja
sed -i 's| [^ ]*g++ | $(CXX) |g' ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja
sed -i 's|"ar"|$(TARGET)-ar|g' ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja
sed 's| [^ ]*gcc | $(CC) |g' ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja > ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja.tmp
cat ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja.tmp > ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja
rm ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja.tmp
sed 's| [^ ]*g++ | $(CXX) |g' ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja > ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja.tmp
cat ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja.tmp > ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja
rm ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja.tmp
sed 's|"ar"|$(TARGET)-ar|g' ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja > ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja.tmp
cat ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja.tmp > ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja
rm ./dep/_google-webrtc/src/out/release-$(TARGET)/toolchain.ninja.tmp
ninja -C ./dep/_google-webrtc/src/out/release-$(TARGET)

check_msquic_dependencies:
sh -c "command -v cmake"

compile_msquic: check_msquic_dependencies update_submodule
mkdir -p ./dep/msquic/$(TARGET)
sed -i 's|\(^ *msquic_lib\)$$|\1 ALL|g' ./dep/msquic/src/bin/CMakeLists.txt
cmake -B./dep/msquic/$(TARGET) -S./dep/msquic -DQUIC_BUILD_SHARED=OFF -DCMAKE_TARGET_ARCHITECTURE=$(TARGET_CPU)
ifeq ($(TARGET_CPU),arm64)
make -C./dep/msquic/$(TARGET) -j$(shell nproc)
@renameSymbols=$$(objdump -t ./dep/msquic/$(TARGET)/bin/Release/libmsquic.a | awk -v RS= '/_YB80VJ/{next}1' | grep -E 'g +(F|O) ' | grep -Evi ' (ms){0,1}quic' | awk '{print " --redefine-sym " $$NF "=" $$NF "_YB80VJ"}') && \
aarch64-linux-gnu-objcopy $$renameSymbols ./dep/msquic/$(TARGET)/bin/Release/libmsquic.a
else
make -C./dep/msquic/$(TARGET) -j$(shell nproc)
@renameSymbols=$$(objdump -t ./dep/msquic/$(TARGET)/bin/Release/libmsquic.a | awk -v RS= '/_YB80VJ/{next}1' | grep -E 'g +(F|O) ' | grep -Evi ' (ms){0,1}quic' | awk '{print " --redefine-sym " $$NF "=" $$NF "_YB80VJ"}') && \
objcopy $$renameSymbols ./dep/msquic/$(TARGET)/bin/Release/libmsquic.a
endif
mkdir -p ./dep/_msquic/$(TARGET)
sed 's|\(^ *msquic_lib\)$$|\1 ALL|g' ./dep/_msquic/src/bin/CMakeLists.txt > ./dep/_msquic/src/bin/CMakeLists.txt.tmp
cat ./dep/_msquic/src/bin/CMakeLists.txt.tmp > ./dep/_msquic/src/bin/CMakeLists.txt
rm ./dep/_msquic/src/bin/CMakeLists.txt.tmp
cmake -B./dep/_msquic/$(TARGET) -S./dep/_msquic -DQUIC_BUILD_SHARED=OFF -DCMAKE_TARGET_ARCHITECTURE=$(TARGET_CPU)
make -C./dep/_msquic/$(TARGET) -j$(shell nproc)
@renameSymbols=$$(objdump -t ./dep/_msquic/$(TARGET)/bin/Release/libmsquic.a | awk -v RS= '/_YB80VJ/{next}1' | grep -E 'g +(F|O) ' | grep -Evi ' (ms){0,1}quic' | awk '{print " --redefine-sym " $$NF "=" $$NF "_YB80VJ"}') && \
$(TARGET)-objcopy $$renameSymbols ./dep/_msquic/$(TARGET)/bin/Release/libmsquic.a
9 changes: 4 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/isrc-cas/gt/conn/msquic"
"io"
"net"
"net/http"
Expand All @@ -43,11 +42,12 @@ import (
"github.com/isrc-cas/gt/client/webrtc"
"github.com/isrc-cas/gt/config"
connection "github.com/isrc-cas/gt/conn"
"github.com/isrc-cas/gt/conn/msquic"
"github.com/isrc-cas/gt/logger"
"github.com/isrc-cas/gt/pool"
"github.com/isrc-cas/gt/predef"
"github.com/isrc-cas/gt/util"
"github.com/shirou/gopsutil/process"
"github.com/shirou/gopsutil/v3/process"
)

// New parses the command line args and creates a Client. out 用于测试
Expand Down Expand Up @@ -386,7 +386,7 @@ func (c *Client) Start() (err error) {
if len(c.Config().Remote) > 0 {
var hasQuic bool
var enterSwitch bool
for index, _ := range c.Config().Remote {
for index := range c.Config().Remote {
if !strings.Contains(c.Config().Remote[index], "://") {
c.Config().Remote[index] = "tcp://" + c.Config().Remote[index]
}
Expand Down Expand Up @@ -633,12 +633,11 @@ func (c *Client) connect(d dialer, connID uint) (closing bool) {
c.idleManager.initMtx.Unlock()
c.Logger.Info().Uint("connID", connID).Msg("wait to connect to remote")
}

c.idleManager.SetWait(connID)
if atomic.LoadUint32(&c.closing) == 1 {
return true
}
time.Sleep(c.Config().ReconnectDelay.Duration)
c.idleManager.SetWait(connID)
c.idleManager.WaitIdle(connID)

for len(c.Config().RemoteAPI) > 0 {
Expand Down
3 changes: 0 additions & 3 deletions client/idle.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ func (m *idleManager) Init(id uint) (exit bool) {
m.statusMtx.Lock()
defer m.statusMtx.Unlock()

if v, ok := m.status[id]; ok && v == connecting {
return false
}
m.status[id] = connecting
var n uint
for _, s := range m.status {
Expand Down
27 changes: 27 additions & 0 deletions config/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package config

import (
"fmt"
"gopkg.in/yaml.v3"
"reflect"
"time"
)
Expand Down Expand Up @@ -69,3 +70,29 @@ func (s *Slice[T]) IsBoolFlag() bool {
_, ok := any(s).(*Slice[bool])
return ok
}

type slice[T BasicType] []T

func (s *Slice[T]) UnmarshalYAML(node *yaml.Node) (err error) {
switch node.Kind {
case yaml.ScalarNode:
var t T
err = node.Decode(&t)
if err != nil {
return
}
*s = make(Slice[T], 1)
(*s)[0] = t
default:
var sv slice[T]
err = node.Decode(&sv)
if err != nil || len(sv) == 0 {
return
}
*s = make(Slice[T], len(sv))
for i, t := range sv {
(*s)[i] = t
}
}
return
}
9 changes: 5 additions & 4 deletions conn/quicConn.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/pem"
"github.com/isrc-cas/gt/predef"
"github.com/quic-go/quic-go"
"math/big"
"net"
"sync/atomic"
"time"

"github.com/isrc-cas/gt/predef"
"github.com/quic-go/quic-go"
)

const probePacketLostTimeOutMs = 5
Expand Down Expand Up @@ -121,7 +122,7 @@ func GetQuicProbesResults(addr string) (avgRtt float64, pktLoss float64, err err

for i := 0; i < totalNum; i++ {
go func() {
err = conn.(*QuicConnection).SendMessage([]byte(time.Now().Format("2006-01-02 15:04:05.000000000")))
err = conn.(*QuicConnection).SendDatagram([]byte(time.Now().Format("2006-01-02 15:04:05.000000000")))
if err != nil {
return
}
Expand All @@ -135,7 +136,7 @@ func GetQuicProbesResults(addr string) (avgRtt float64, pktLoss float64, err err
return
}
})
buf, err = conn.(*QuicConnection).ReceiveMessage()
buf, err = conn.(*QuicConnection).ReceiveDatagram(context.Background())
if err != nil {
// QUIC的stream关闭时会返回io.EOF,但是QUIC的不可靠数据包Datagram是在connection层面进行发送的
// 因此需要通过quic.ApplicationError判断QUIC connection是否由于应用程序主动关闭
Expand Down
Loading

0 comments on commit b5f5601

Please sign in to comment.