buffge commited on
Commit
da19377
·
1 Parent(s): fcb4374
Files changed (5) hide show
  1. Dockerfile +3 -17
  2. Dockerfile-go +21 -0
  3. README.md +1 -11
  4. cmd/rtc-signaling/main.go +39 -3
  5. squid.conf +75 -0
Dockerfile CHANGED
@@ -1,21 +1,7 @@
1
- FROM golang:1.22.3-alpine as builder
2
-
3
- COPY . /work
4
- WORKDIR /work
5
- RUN go mod tidy && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags=sonic -ldflags "-s -w \
6
- -extldflags "-static" \
7
- " -o bin/rtc-signaling cmd/rtc-signaling/main.go
8
-
9
- FROM alpine:3.20
10
-
11
- MAINTAINER buffge "admin@buffge.com"
12
-
13
  ENV LANG=C.UTF-8 TZ=Asia/Shanghai
14
- LABEL commitMsg=${commitMsg}
15
 
16
- WORKDIR /work
17
- COPY --from=builder /work/bin /work/bin
18
- #COPY --from=builder /work/etc /work/etc
19
  EXPOSE 7860
 
20
 
21
- ENTRYPOINT ["./bin/rtc-signaling"]
 
1
+ FROM ubuntu/squid:5.2-22.04_beta
 
 
 
 
 
 
 
 
 
 
 
2
  ENV LANG=C.UTF-8 TZ=Asia/Shanghai
 
3
 
 
 
 
4
  EXPOSE 7860
5
+ COPY ./squid.conf /etc/squid/squid.conf
6
 
7
+ #ENTRYPOINT ["top", "-b"]
Dockerfile-go ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM golang:1.22.3-alpine as builder
2
+
3
+ COPY . /work
4
+ WORKDIR /work
5
+ RUN go mod tidy && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags=sonic -ldflags "-s -w \
6
+ -extldflags "-static" \
7
+ " -o bin/rtc-signaling cmd/rtc-signaling/main.go
8
+
9
+ FROM alpine:3.20
10
+
11
+ MAINTAINER buffge "admin@buffge.com"
12
+
13
+ ENV LANG=C.UTF-8 TZ=Asia/Shanghai
14
+ LABEL commitMsg=${commitMsg}
15
+
16
+ WORKDIR /work
17
+ COPY --from=builder /work/bin /work/bin
18
+ #COPY --from=builder /work/etc /work/etc
19
+ EXPOSE 7860
20
+
21
+ ENTRYPOINT ["./bin/rtc-signaling"]
README.md CHANGED
@@ -1,11 +1 @@
1
- ---
2
- title: Docker 1
3
- emoji: 🏆
4
- colorFrom: purple
5
- colorTo: purple
6
- sdk: docker
7
- pinned: false
8
- license: apache-2.0
9
- ---
10
-
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ # buff hf
 
 
 
 
 
 
 
 
 
 
cmd/rtc-signaling/main.go CHANGED
@@ -1,16 +1,33 @@
1
  package main
2
 
3
  import (
 
4
  "github.com/gorilla/websocket"
5
  "log"
6
  "net/http"
7
  "rtc-signaling/api"
 
 
8
  )
9
 
10
  var upgrader = websocket.Upgrader{
11
  ReadBufferSize: 1024,
12
  WriteBufferSize: 1024,
13
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  func main() {
16
  http.HandleFunc("/", api.DevTest)
@@ -29,14 +46,33 @@ func main() {
29
  log.Fatal("ListenAndServe: ", err)
30
  }
31
  }
 
 
 
 
 
 
 
32
  func handleConn(conn *websocket.Conn) {
33
  defer conn.Close()
 
 
 
34
  for {
35
- mt, msg, err := conn.ReadMessage()
 
 
 
36
  if err != nil {
37
- _ = conn.Close()
38
  return
39
  }
40
- _ = conn.WriteMessage(mt, msg)
 
 
 
 
 
 
41
  }
42
  }
 
1
  package main
2
 
3
  import (
4
+ "encoding/json"
5
  "github.com/gorilla/websocket"
6
  "log"
7
  "net/http"
8
  "rtc-signaling/api"
9
+ "sync"
10
+ "sync/atomic"
11
  )
12
 
13
  var upgrader = websocket.Upgrader{
14
  ReadBufferSize: 1024,
15
  WriteBufferSize: 1024,
16
  }
17
+ var (
18
+ connMap = map[*websocket.Conn]struct{}{}
19
+ mu = &sync.Mutex{}
20
+ roomIDAtomic = atomic.Uint32{}
21
+ )
22
+
23
+ type (
24
+ Message struct {
25
+ Type int `json:"type"`
26
+ Data json.RawMessage `json:"data"`
27
+ }
28
+ CreateRoomMsg struct {
29
+ }
30
+ )
31
 
32
  func main() {
33
  http.HandleFunc("/", api.DevTest)
 
46
  log.Fatal("ListenAndServe: ", err)
47
  }
48
  }
49
+ func closeConn(conn *websocket.Conn) {
50
+ mu.Lock()
51
+ delete(connMap, conn)
52
+ mu.Unlock()
53
+ _ = conn.Close()
54
+ return
55
+ }
56
  func handleConn(conn *websocket.Conn) {
57
  defer conn.Close()
58
+ mu.Lock()
59
+ connMap[conn] = struct{}{}
60
+ mu.Unlock()
61
  for {
62
+ mt, bts, err := conn.ReadMessage()
63
+ if mt != websocket.TextMessage {
64
+ continue
65
+ }
66
  if err != nil {
67
+ closeConn(conn)
68
  return
69
  }
70
+ msg := &Message{}
71
+ err = json.Unmarshal(bts, msg)
72
+ if err != nil {
73
+ continue
74
+ }
75
+ switch msg.Type {
76
+ }
77
  }
78
  }
squid.conf ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # Recommended minimum configuration:
3
+ #
4
+
5
+ # Example rule allowing access from your local networks.
6
+ # Adapt to list your (internal) IP networks from where browsing
7
+ # should be allowed
8
+ acl localnet src 0.0.0.1-0.255.255.255 # RFC 1122 "this" network (LAN)
9
+ acl localnet src 10.0.0.0/8 # RFC 1918 local private network (LAN)
10
+ acl localnet src 100.64.0.0/10 # RFC 6598 shared address space (CGN)
11
+ acl localnet src 169.254.0.0/16 # RFC 3927 link-local (directly plugged) machines
12
+ acl localnet src 172.16.0.0/12 # RFC 1918 local private network (LAN)
13
+ acl localnet src 192.168.0.0/16 # RFC 1918 local private network (LAN)
14
+ acl localnet src fc00::/7 # RFC 4193 local private network range
15
+ acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
16
+
17
+ acl SSL_ports port 443
18
+ acl Safe_ports port 80 # http
19
+ acl Safe_ports port 21 # ftp
20
+ acl Safe_ports port 443 # https
21
+ acl Safe_ports port 70 # gopher
22
+ acl Safe_ports port 210 # wais
23
+ acl Safe_ports port 1025-65535 # unregistered ports
24
+ acl Safe_ports port 280 # http-mgmt
25
+ acl Safe_ports port 488 # gss-http
26
+ acl Safe_ports port 591 # filemaker
27
+ acl Safe_ports port 777 # multiling http
28
+ acl CONNECT method CONNECT
29
+
30
+ #
31
+ # Recommended minimum Access Permission configuration:
32
+ #
33
+ # Deny requests to certain unsafe ports
34
+ http_access deny !Safe_ports
35
+
36
+ # Deny CONNECT to other than secure SSL ports
37
+ http_access deny CONNECT !SSL_ports
38
+
39
+ # Only allow cachemgr access from localhost
40
+ http_access allow localhost manager
41
+ http_access deny manager
42
+
43
+ # We strongly recommend the following be uncommented to protect innocent
44
+ # web applications running on the proxy server who think the only
45
+ # one who can access services on "localhost" is a local user
46
+ #http_access deny to_localhost
47
+
48
+ #
49
+ # INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
50
+ #
51
+
52
+ # Example rule allowing access from your local networks.
53
+ # Adapt localnet in the ACL section to list your (internal) IP networks
54
+ # from where browsing should be allowed
55
+ http_access allow localnet
56
+ http_access allow localhost
57
+
58
+ # And finally deny all other access to this proxy
59
+ http_access deny all
60
+
61
+ # Squid normally listens to port 3128
62
+ http_port 7860
63
+
64
+ # Uncomment and adjust the following to add a disk cache directory.
65
+ #cache_dir ufs /var/spool/squid 100 16 256
66
+
67
+ # Leave coredumps in the first cache dir
68
+ coredump_dir /var/spool/squid
69
+
70
+ #
71
+ # Add any of your own refresh_pattern entries above these.
72
+ #
73
+ refresh_pattern ^ftp: 1440 20% 10080
74
+ refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
75
+ refresh_pattern . 0 20% 4320