跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

protocols.go

79 行 · 1.4 KB历史下载
1package tap
2
3import (
4 "encoding/binary"
5 "math"
6
7 log "github.com/sirupsen/logrus"
8)
9
10type protocol interface {
11 Stream() bool
12}
13
14type streamProtocol interface {
15 protocol
16 Buf() []byte
17 Write(buf []byte, size int)
18 Read(buf []byte) int
19}
20
21type hyperkitProtocol struct {
22}
23
24func (s *hyperkitProtocol) Stream() bool {
25 return true
26}
27
28func (s *hyperkitProtocol) Buf() []byte {
29 return make([]byte, 2)
30}
31
32func (s *hyperkitProtocol) Write(buf []byte, size int) {
33 if size < 0 || size > math.MaxUint16 {
34 log.Warnf("size out of range. Resetting to %d", math.MaxUint16)
35 size = math.MaxUint16
36 }
37 binary.LittleEndian.PutUint16(buf, uint16(size)) //#nosec: G115
38}
39
40func (s *hyperkitProtocol) Read(buf []byte) int {
41 return int(binary.LittleEndian.Uint16(buf[0:2]))
42}
43
44type qemuProtocol struct {
45}
46
47func (s *qemuProtocol) Stream() bool {
48 return true
49}
50
51func (s *qemuProtocol) Buf() []byte {
52 return make([]byte, 4)
53}
54
55func (s *qemuProtocol) Write(buf []byte, size int) {
56 if size > math.MaxInt32 {
57 log.Warnf("size exceeds max limit. Resetting to: %d", math.MaxInt32)
58 size = math.MaxInt32
59 }
60 binary.BigEndian.PutUint32(buf, uint32(size)) //#nosec: G115. Safely checked
61}
62
63func (s *qemuProtocol) Read(buf []byte) int {
64 return int(binary.BigEndian.Uint32(buf[0:4]))
65}
66
67type bessProtocol struct {
68}
69
70func (s *bessProtocol) Stream() bool {
71 return false
72}
73
74type vfkitProtocol struct {
75}
76
77func (s *vfkitProtocol) Stream() bool {
78 return false
79}