Skip to content

Commit

Permalink
重构:更新
Browse files Browse the repository at this point in the history
  • Loading branch information
guonaihong committed Jun 27, 2023
1 parent e6394eb commit 2ea4c89
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 35 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*swp
autobahn-testsuite
autobahn-testsuite-darwin-arm64
autobahn-testsuite-linux-amd64
autobahn-client-testsuite-darwin-arm64
autobahn-client-testsuite-linux-amd64
autobahn-server-testsuite-darwin-arm64
autobahn-server-testsuite-linux-amd64
cpu.profile
mem.profile
14 changes: 12 additions & 2 deletions autobahn/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
all:
# mac, arm64
GOOS=darwin GOARCH=arm64 go build -o autobahn-testsuite-darwin-arm64 ./autobahn-testsuite.go
GOOS=darwin GOARCH=arm64 go build -o autobahn-server-testsuite-darwin-arm64 ./autobahn-server-testsuite.go
# linux amd64
GOOS=linux GOARCH=amd64 go build -o autobahn-testsuite-linux-amd64 ./autobahn-testsuite.go
GOOS=linux GOARCH=amd64 go build -o autobahn-server-testsuite-linux-amd64 ./autobahn-server-testsuite.go

# mac, arm64
GOOS=darwin GOARCH=arm64 go build -o autobahn-client-testsuite-darwin-arm64 ./autobahn-client-testsuite.go
# linux amd64
GOOS=linux GOARCH=amd64 go build -o autobahn-client-testsuite-linux-amd64 ./autobahn-client-testsuite.go

key:
openssl genrsa 2048 > privatekey.pem
openssl req -new -key privatekey.pem -out csr.pem
openssl x509 -req -days 36500 -in csr.pem -signkey privatekey.pem -out public.crt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build tinywstest
// +build tinywstest

package main

import (
Expand All @@ -9,9 +6,10 @@ import (
"time"

"github.com/antlabs/quickws"
//"os"
)

// https://github.com/snapview/tokio-tungstenite/blob/master/examples/autobahn-client.rs

type echoHandler struct{}

func (e *echoHandler) OnOpen(c *quickws.Conn) {
Expand Down Expand Up @@ -46,7 +44,11 @@ func echo(w http.ResponseWriter, r *http.Request) {
}

func main() {
http.HandleFunc("/", echo)
c, err := quickws.Dial("ws://127.0.0.1:9003", quickws.WithClientCallback(&echoHandler{}))
if err != nil {
fmt.Println("Dial fail:", err)
return
}

http.ListenAndServe(":9001", nil)
c.ReadLoop()
}
85 changes: 85 additions & 0 deletions autobahn/autobahn-server-testsuite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//go:build quickwstest
// +build quickwstest

package main

import (
"crypto/tls"
_ "embed"
"fmt"
"log"
"net"
"net/http"
"time"

"github.com/antlabs/quickws"
//"os"
)

//go:embed public.crt
var certPEMBlock []byte

//go:embed privatekey.pem
var keyPEMBlock []byte

type echoHandler struct{}

func (e *echoHandler) OnOpen(c *quickws.Conn) {
fmt.Println("OnOpen:", c)
}

func (e *echoHandler) OnMessage(c *quickws.Conn, op quickws.Opcode, msg []byte) {
// fmt.Println("OnMessage:", c, msg, op)
if err := c.WriteTimeout(op, msg, 3*time.Second); err != nil {
fmt.Println("write fail:", err)
}
}

func (e *echoHandler) OnClose(c *quickws.Conn, err error) {
fmt.Println("OnClose:", c, err)
}

// echo测试服务
func echo(w http.ResponseWriter, r *http.Request) {
c, err := quickws.Upgrade(w, r, quickws.WithServerReplyPing(),
quickws.WithServerDecompression(),
quickws.WithServerIgnorePong(),
quickws.WithServerCallback(&echoHandler{}),
quickws.WithServerReadTimeout(5*time.Second),
)
if err != nil {
fmt.Println("Upgrade fail:", err)
return
}

c.ReadLoop()
}

func main() {
mux := &http.ServeMux{}
mux.HandleFunc("/autobahn", echo)

rawTCP, err := net.Listen("tcp", "localhost:9001")
if err != nil {
fmt.Println("Listen fail:", err)
return
}

go func() {
log.Println("non-tls server exit:", http.Serve(rawTCP, mux))
}()

cert, err := tls.X509KeyPair(certPEMBlock, keyPEMBlock)
if err != nil {
log.Fatalf("tls.X509KeyPair failed: %v", err)
}
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
InsecureSkipVerify: true,
}
lnTLS, err := tls.Listen("tcp", "localhost:9002", tlsConfig)
if err != nil {
panic(err)
}
log.Println("tls server exit:", http.Serve(lnTLS, mux))
}
51 changes: 26 additions & 25 deletions autobahn/config/fuzzingclient.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
{
"outdir": "./report/",
"servers": [
{
"agent": "non-tls",
"url": "ws://localhost:9000/connect",
"options": {
"version": 18
}
},
{
"agent": "tls",
"url": "wss://localhost:9001/connect",
"options": {
"version": 18
}
}
],
"cases": [
"*"
],
"exclude-cases": [
"1[1-4].*"
],
"exclude-agent-cases": {}
}
"outdir": "./report/",
"servers": [
{
"agent": "non-tls",
"url": "ws://localhost:9001/autobahn",
"options": {
"version": 18
}
},
{
"agent": "tls",
"url": "wss://localhost:9002/autobahn",
"options": {
"version": 18
}
}
],
"cases": [
"*"
],
"exclude-cases": [
""
],
"exclude-agent-cases": {}
}

16 changes: 16 additions & 0 deletions autobahn/csr.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-----BEGIN CERTIFICATE REQUEST-----
MIICeDCCAWACAQAwMzELMAkGA1UEBhMCY24xETAPBgNVBAgMCHNoYW5naGFpMREw
DwYDVQQHDAhzaGFuZ2hhaTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
AL+UkOo23qO2W9r1fHcxk0wtXvmnbx1Arf5IMaoJXN6prCr8NDKjt9Y2/7PyPBwB
hRewGhGut7EmCr/WnHT9rKa4pSYwk+fAEMY3KQbVyjA6v6rID87K5JEN132vqN6g
3VrTwV7yS5vhx43HmASUutpwtf2f9GM4ptQcmzdUvMALiPx515J7szCAUVh1R+4v
my5eSZ+fqhcemLE1xAzNsUn0EMa56eF7zwfVpuQn6OWBUC5+WpR6rVnSgMABLhY/
Bct3OAk0jsftG7SCZPb6v0YTMMpHD8PT/uHXe/VNbSMJJ+s+4L8zAjJW8zQXtkOh
//0rba4khzqF++ffPsK3kLcCAwEAAaAAMA0GCSqGSIb3DQEBCwUAA4IBAQCn6WhR
sj9NI6XD0S8PwYCmSDfDYq+DKFUP3UQujm6Wlaj5Cd0qURmaj/Zonh+fDOGke9AK
iKwIBom/3BWviAlIeRUQpdvBR8nCcQImlan0ttiFzNn72GqlAcYAVo9VZzLZAnxS
jVV7+RQlttQ4zmCPJ1P3xz1sC81c3Pt6f89N1MZbtk/EfDFplLaEKuCOHn8CasRp
KSLeidChYB5uw2ZzEN473huN0iVSZmFVF4gXB7OWYrCahsltJdBTBLCfNgeTuxY0
br0wfFi/TbQCOxsvEe07HbX58NDB0zwL2PnNGpzpbaNVUa09/JJ1v9mv8xkoFAe9
dzrWlhVI1/YLJ8oG
-----END CERTIFICATE REQUEST-----
27 changes: 27 additions & 0 deletions autobahn/privatekey.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAv5SQ6jbeo7Zb2vV8dzGTTC1e+advHUCt/kgxqglc3qmsKvw0
MqO31jb/s/I8HAGFF7AaEa63sSYKv9acdP2sprilJjCT58AQxjcpBtXKMDq/qsgP
zsrkkQ3Xfa+o3qDdWtPBXvJLm+HHjceYBJS62nC1/Z/0Yzim1BybN1S8wAuI/HnX
knuzMIBRWHVH7i+bLl5Jn5+qFx6YsTXEDM2xSfQQxrnp4XvPB9Wm5Cfo5YFQLn5a
lHqtWdKAwAEuFj8Fy3c4CTSOx+0btIJk9vq/RhMwykcPw9P+4dd79U1tIwkn6z7g
vzMCMlbzNBe2Q6H//SttriSHOoX7598+wreQtwIDAQABAoIBAQCKVKLCizX9Ldpr
YqApjIFYGtaeG1iu3ZoEpmo95Z7KI+dt7kdeXTqLkZDWhM0ER9CrBvv70pVOczKF
zFeSXezBQUf2KFNTnio+hWu5RLtGUdU9YlGPto6NclorpZ+giLTsNURF41vWxZMK
e5j3jdDRk1rFNC8JScmkFLe6nxPe8fPvCjLGQx2yuMYHlnvgmrIEuWiPHaziP4yU
tBKQpCxmruljJvQ503BZtW3g/XlktwR4lexuIOn624nLWla8+ryn+cquEV3FTiKp
WwHJYAVlVaaJbsefmiz9tDkUV2PHDgov3u/Eth/C3HdW0qJC0X+/uiLY0/3Z0O3w
h0M7Y8wpAoGBAPRNymCrG0DKKJLIBB0B+++SNRsR5D1rE74Ig043ax836lVy+2wS
5aJu7wSbfIAEei2iGhvcV6ePHK0LyDXBaGUOF2/QnhCz7nI7D++E9K7hYRNzUllk
L8JgEj9BrIoruED/Y81TQ3HNi9JXp82Oqnpa9/dvd3tGWT1UqIFKGNRrAoGBAMjA
l2F6cGEOgBOEyrbt60h2ErlXPMIOaFUAaLePOdmv3RQQkWoYOjouPcXUbQ22Bc2Z
edSLip2OTm4hCSbcIYpKViH+NxiMMQnvWfTtO/rdlvPQKYBi9BaNTvvxTcIONMT6
9v+D5u1mbnIPv/PuDvW5hKUCArrUHfzXDsuFv+flAoGAcwx7RODveah6SP12qm53
xY+WAMSBNsdJSdHafCgvA0miylDWxEN17vPNDd9nVyZEn17aaspuYRNNTtTgmSgW
0Jg9Q0P8XCNQJG1aCNMVI5Ix1CYX3s8GisQRc8aqyXrjT4C18EjI1zwUH591/6Cy
+eIDKnxMyToM5owKurA5VzcCgYBPnlJrjqvTUnTpSNk9A880xd9XMooeTKiETc06
P8up0l3T/14svb8aJAzL0RwPPAnBKQVwjodDRZVFiESg7N1Ag4r1oGUpjzBDyHHc
+dm3/PpJaF2NVbGI4DJbKbC1Lf0vwnkDjcSgkudqxWRT0i6Mti8tYkbC4i2igYiU
n08lIQKBgQCt4vxZ6nHEd/uIhYal/+dla75rob44/itn+ASELpyyZ3FNYlcnbkLu
JsIRiBLPerUX70HHn49eA3ilGTT3YKmy52rhfg/bTy+elDPyVcevXtLzeNLc/xYX
Mw2fsZ/vXG9rQcP3oPfHKijMywLahXgaVshMHM9Rtm8+cG1OO75k7g==
-----END RSA PRIVATE KEY-----
18 changes: 18 additions & 0 deletions autobahn/public.crt
Original file line number Diff line number Diff line change
@@ -0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