slidge-whatsapp 0.3.7__cp312-cp312-manylinux_2_41_aarch64.whl → 0.3.8__cp312-cp312-manylinux_2_41_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. slidge_whatsapp/config.py +7 -2
  2. slidge_whatsapp/contact.py +3 -2
  3. slidge_whatsapp/event.go +14 -9
  4. slidge_whatsapp/gateway.go +7 -1
  5. slidge_whatsapp/generated/_whatsapp.cpython-312-aarch64-linux-gnu.h +182 -178
  6. slidge_whatsapp/generated/_whatsapp.cpython-312-aarch64-linux-gnu.so +0 -0
  7. slidge_whatsapp/generated/build.py +146 -142
  8. slidge_whatsapp/generated/whatsapp.c +1456 -1376
  9. slidge_whatsapp/generated/whatsapp.go +1069 -1045
  10. slidge_whatsapp/generated/whatsapp.py +1324 -1298
  11. slidge_whatsapp/generated/whatsapp_go.h +182 -178
  12. slidge_whatsapp/go.mod +6 -6
  13. slidge_whatsapp/go.sum +12 -12
  14. slidge_whatsapp/group.py +25 -0
  15. slidge_whatsapp/session.go +69 -67
  16. slidge_whatsapp/session.py +11 -1
  17. slidge_whatsapp/vendor/github.com/coder/websocket/LICENSE.txt +13 -0
  18. slidge_whatsapp/vendor/github.com/coder/websocket/Makefile +18 -0
  19. slidge_whatsapp/vendor/github.com/coder/websocket/README.md +162 -0
  20. slidge_whatsapp/vendor/github.com/coder/websocket/accept.go +378 -0
  21. slidge_whatsapp/vendor/github.com/coder/websocket/close.go +335 -0
  22. slidge_whatsapp/vendor/github.com/coder/websocket/compress.go +234 -0
  23. slidge_whatsapp/vendor/github.com/coder/websocket/conn.go +306 -0
  24. slidge_whatsapp/vendor/github.com/coder/websocket/dial.go +347 -0
  25. slidge_whatsapp/vendor/github.com/coder/websocket/doc.go +33 -0
  26. slidge_whatsapp/vendor/github.com/coder/websocket/errors.go +8 -0
  27. slidge_whatsapp/vendor/github.com/coder/websocket/frame.go +173 -0
  28. slidge_whatsapp/vendor/github.com/coder/websocket/hijack.go +33 -0
  29. slidge_whatsapp/vendor/github.com/coder/websocket/internal/bpool/bpool.go +25 -0
  30. slidge_whatsapp/vendor/github.com/coder/websocket/internal/errd/wrap.go +14 -0
  31. slidge_whatsapp/vendor/github.com/coder/websocket/internal/util/util.go +15 -0
  32. slidge_whatsapp/vendor/github.com/coder/websocket/internal/wsjs/wsjs_js.go +169 -0
  33. slidge_whatsapp/vendor/github.com/coder/websocket/mask.go +128 -0
  34. slidge_whatsapp/vendor/github.com/coder/websocket/mask_amd64.s +127 -0
  35. slidge_whatsapp/vendor/github.com/coder/websocket/mask_arm64.s +72 -0
  36. slidge_whatsapp/vendor/github.com/coder/websocket/mask_asm.go +26 -0
  37. slidge_whatsapp/vendor/github.com/coder/websocket/mask_go.go +7 -0
  38. slidge_whatsapp/vendor/github.com/coder/websocket/netconn.go +233 -0
  39. slidge_whatsapp/vendor/github.com/coder/websocket/netconn_js.go +11 -0
  40. slidge_whatsapp/vendor/github.com/coder/websocket/netconn_notjs.go +19 -0
  41. slidge_whatsapp/vendor/github.com/coder/websocket/read.go +540 -0
  42. slidge_whatsapp/vendor/github.com/coder/websocket/stringer.go +91 -0
  43. slidge_whatsapp/vendor/github.com/coder/websocket/write.go +384 -0
  44. slidge_whatsapp/vendor/github.com/coder/websocket/ws_js.go +598 -0
  45. slidge_whatsapp/vendor/github.com/ebitengine/purego/func.go +1 -1
  46. slidge_whatsapp/vendor/github.com/ebitengine/purego/struct_amd64.go +1 -1
  47. slidge_whatsapp/vendor/github.com/ebitengine/purego/struct_arm64.go +3 -1
  48. slidge_whatsapp/vendor/github.com/ebitengine/purego/struct_loong64.go +1 -1
  49. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/directive.go +3 -0
  50. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/selection.go +3 -0
  51. slidge_whatsapp/vendor/github.com/vektah/gqlparser/v2/ast/value.go +4 -3
  52. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate/encode.go +3 -0
  53. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/appstate.go +18 -4
  54. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/broadcast.go +3 -3
  55. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/call.go +6 -4
  56. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/client.go +90 -80
  57. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/connectionevents.go +14 -11
  58. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/download.go +4 -1
  59. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/group.go +47 -48
  60. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/handshake.go +3 -2
  61. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/internals.go +79 -75
  62. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/keepalive.go +8 -6
  63. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/mediaconn.go +1 -2
  64. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/mediaretry.go +2 -2
  65. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/message.go +42 -40
  66. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/newsletter.go +35 -32
  67. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/notification.go +2 -3
  68. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/pair-code.go +2 -4
  69. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/pair.go +19 -19
  70. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/prekeys.go +9 -8
  71. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/presence.go +9 -9
  72. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/privacysettings.go +4 -5
  73. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloAddMessage/InstamadilloAddMessage.pb.go +1 -1
  74. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeActionLog/InstamadilloCoreTypeActionLog.pb.go +1 -1
  75. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeAdminMessage/InstamadilloCoreTypeAdminMessage.pb.go +1 -1
  76. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeCollection/InstamadilloCoreTypeCollection.pb.go +1 -1
  77. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeLink/InstamadilloCoreTypeLink.pb.go +1 -1
  78. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeMedia/InstamadilloCoreTypeMedia.pb.go +1 -1
  79. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloCoreTypeText/InstamadilloCoreTypeText.pb.go +1 -1
  80. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloDeleteMessage/InstamadilloDeleteMessage.pb.go +1 -1
  81. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloSupplementMessage/InstamadilloSupplementMessage.pb.go +1 -1
  82. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloTransportPayload/InstamadilloTransportPayload.pb.go +1 -1
  83. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/instamadilloXmaContentRef/InstamadilloXmaContentRef.pb.go +1 -1
  84. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waAICommon/WAAICommon.pb.go +1145 -335
  85. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waAICommon/WAAICommon.proto +78 -0
  86. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waAdv/WAAdv.pb.go +1 -1
  87. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waArmadilloApplication/WAArmadilloApplication.pb.go +1 -1
  88. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waArmadilloXMA/WAArmadilloXMA.pb.go +1 -1
  89. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCert/WACert.pb.go +1 -1
  90. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waChatLockSettings/WAProtobufsChatLockSettings.pb.go +1 -1
  91. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCommon/WACommon.pb.go +1 -1
  92. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCompanionReg/WACompanionReg.pb.go +22 -4
  93. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waCompanionReg/WACompanionReg.proto +2 -0
  94. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waConsumerApplication/WAConsumerApplication.pb.go +1 -1
  95. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waDeviceCapabilities/WAProtobufsDeviceCapabilities.pb.go +104 -30
  96. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waDeviceCapabilities/WAProtobufsDeviceCapabilities.proto +7 -0
  97. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waE2E/WAWebProtobufsE2E.pb.go +1037 -963
  98. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waE2E/WAWebProtobufsE2E.proto +15 -8
  99. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waHistorySync/WAWebProtobufsHistorySync.pb.go +1 -1
  100. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waLidMigrationSyncPayload/WAWebProtobufLidMigrationSyncPayload.pb.go +1 -1
  101. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMediaTransport/WAMediaTransport.pb.go +1 -1
  102. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMmsRetry/WAMmsRetry.pb.go +1 -1
  103. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMsgApplication/WAMsgApplication.pb.go +1 -1
  104. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMsgTransport/WAMsgTransport.pb.go +1 -1
  105. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waMultiDevice/WAMultiDevice.pb.go +1 -1
  106. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waServerSync/WAServerSync.pb.go +1 -1
  107. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waStatusAttributions/WAStatusAttributions.pb.go +40 -35
  108. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waStatusAttributions/WAStatusAttributions.proto +1 -0
  109. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waSyncAction/WASyncAction.pb.go +921 -653
  110. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waSyncAction/WASyncAction.proto +44 -15
  111. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waUserPassword/WAProtobufsUserPassword.pb.go +1 -1
  112. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waVnameCert/WAWebProtobufsVnameCert.pb.go +1 -1
  113. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWa6/WAWebProtobufsWa6.pb.go +9 -5
  114. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWa6/WAWebProtobufsWa6.proto +1 -0
  115. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWeb/WAWebProtobufsWeb.pb.go +193 -115
  116. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/proto/waWeb/WAWebProtobufsWeb.proto +9 -0
  117. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/push.go +2 -4
  118. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/receipt.go +12 -12
  119. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/request.go +25 -19
  120. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/retry.go +2 -2
  121. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/send.go +43 -27
  122. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/sendfb.go +4 -4
  123. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/socket/constants.go +1 -1
  124. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/socket/framesocket.go +43 -56
  125. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/socket/noisehandshake.go +9 -3
  126. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/socket/noisesocket.go +36 -22
  127. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/clientpayload.go +24 -4
  128. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/store/store.go +12 -0
  129. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/types/events/appstate.go +2 -1
  130. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/upload.go +1 -1
  131. slidge_whatsapp/vendor/go.mau.fi/whatsmeow/user.go +79 -40
  132. slidge_whatsapp/vendor/golang.org/x/sys/unix/mkerrors.sh +2 -0
  133. slidge_whatsapp/vendor/golang.org/x/sys/unix/syscall_linux.go +6 -0
  134. slidge_whatsapp/vendor/golang.org/x/sys/unix/zerrors_linux.go +359 -0
  135. slidge_whatsapp/vendor/golang.org/x/sys/unix/zsyscall_linux.go +10 -0
  136. slidge_whatsapp/vendor/golang.org/x/sys/unix/ztypes_linux.go +31 -0
  137. slidge_whatsapp/vendor/golang.org/x/sys/windows/syscall_windows.go +15 -0
  138. slidge_whatsapp/vendor/golang.org/x/sys/windows/types_windows.go +76 -0
  139. slidge_whatsapp/vendor/golang.org/x/sys/windows/zsyscall_windows.go +37 -0
  140. slidge_whatsapp/vendor/modules.txt +12 -8
  141. {slidge_whatsapp-0.3.7.dist-info → slidge_whatsapp-0.3.8.dist-info}/METADATA +1 -1
  142. {slidge_whatsapp-0.3.7.dist-info → slidge_whatsapp-0.3.8.dist-info}/RECORD +145 -136
  143. slidge_whatsapp/vendor/github.com/gorilla/websocket/.gitignore +0 -25
  144. slidge_whatsapp/vendor/github.com/gorilla/websocket/AUTHORS +0 -9
  145. slidge_whatsapp/vendor/github.com/gorilla/websocket/LICENSE +0 -22
  146. slidge_whatsapp/vendor/github.com/gorilla/websocket/README.md +0 -33
  147. slidge_whatsapp/vendor/github.com/gorilla/websocket/client.go +0 -434
  148. slidge_whatsapp/vendor/github.com/gorilla/websocket/compression.go +0 -148
  149. slidge_whatsapp/vendor/github.com/gorilla/websocket/conn.go +0 -1238
  150. slidge_whatsapp/vendor/github.com/gorilla/websocket/doc.go +0 -227
  151. slidge_whatsapp/vendor/github.com/gorilla/websocket/join.go +0 -42
  152. slidge_whatsapp/vendor/github.com/gorilla/websocket/json.go +0 -60
  153. slidge_whatsapp/vendor/github.com/gorilla/websocket/mask.go +0 -55
  154. slidge_whatsapp/vendor/github.com/gorilla/websocket/mask_safe.go +0 -16
  155. slidge_whatsapp/vendor/github.com/gorilla/websocket/prepared.go +0 -102
  156. slidge_whatsapp/vendor/github.com/gorilla/websocket/proxy.go +0 -77
  157. slidge_whatsapp/vendor/github.com/gorilla/websocket/server.go +0 -365
  158. slidge_whatsapp/vendor/github.com/gorilla/websocket/tls_handshake.go +0 -21
  159. slidge_whatsapp/vendor/github.com/gorilla/websocket/tls_handshake_116.go +0 -21
  160. slidge_whatsapp/vendor/github.com/gorilla/websocket/util.go +0 -298
  161. slidge_whatsapp/vendor/github.com/gorilla/websocket/x_net_proxy.go +0 -473
  162. {slidge_whatsapp-0.3.7.dist-info → slidge_whatsapp-0.3.8.dist-info}/WHEEL +0 -0
  163. {slidge_whatsapp-0.3.7.dist-info → slidge_whatsapp-0.3.8.dist-info}/entry_points.txt +0 -0
  164. {slidge_whatsapp-0.3.7.dist-info → slidge_whatsapp-0.3.8.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,72 @@
1
+ #include "textflag.h"
2
+
3
+ // func maskAsm(b *byte, len int, key uint32)
4
+ TEXT ·maskAsm(SB), NOSPLIT, $0-28
5
+ // R0 = b
6
+ // R1 = len
7
+ // R3 = key (uint32)
8
+ // R2 = uint64(key)<<32 | uint64(key)
9
+ MOVD b_ptr+0(FP), R0
10
+ MOVD b_len+8(FP), R1
11
+ MOVWU key+16(FP), R3
12
+ MOVD R3, R2
13
+ ORR R2<<32, R2, R2
14
+ VDUP R2, V0.D2
15
+ CMP $64, R1
16
+ BLT less_than_64
17
+
18
+ loop_64:
19
+ VLD1 (R0), [V1.B16, V2.B16, V3.B16, V4.B16]
20
+ VEOR V1.B16, V0.B16, V1.B16
21
+ VEOR V2.B16, V0.B16, V2.B16
22
+ VEOR V3.B16, V0.B16, V3.B16
23
+ VEOR V4.B16, V0.B16, V4.B16
24
+ VST1.P [V1.B16, V2.B16, V3.B16, V4.B16], 64(R0)
25
+ SUBS $64, R1
26
+ CMP $64, R1
27
+ BGE loop_64
28
+
29
+ less_than_64:
30
+ CBZ R1, end
31
+ TBZ $5, R1, less_than_32
32
+ VLD1 (R0), [V1.B16, V2.B16]
33
+ VEOR V1.B16, V0.B16, V1.B16
34
+ VEOR V2.B16, V0.B16, V2.B16
35
+ VST1.P [V1.B16, V2.B16], 32(R0)
36
+
37
+ less_than_32:
38
+ TBZ $4, R1, less_than_16
39
+ LDP (R0), (R11, R12)
40
+ EOR R11, R2, R11
41
+ EOR R12, R2, R12
42
+ STP.P (R11, R12), 16(R0)
43
+
44
+ less_than_16:
45
+ TBZ $3, R1, less_than_8
46
+ MOVD (R0), R11
47
+ EOR R2, R11, R11
48
+ MOVD.P R11, 8(R0)
49
+
50
+ less_than_8:
51
+ TBZ $2, R1, less_than_4
52
+ MOVWU (R0), R11
53
+ EORW R2, R11, R11
54
+ MOVWU.P R11, 4(R0)
55
+
56
+ less_than_4:
57
+ TBZ $1, R1, less_than_2
58
+ MOVHU (R0), R11
59
+ EORW R3, R11, R11
60
+ MOVHU.P R11, 2(R0)
61
+ RORW $16, R3
62
+
63
+ less_than_2:
64
+ TBZ $0, R1, end
65
+ MOVBU (R0), R11
66
+ EORW R3, R11, R11
67
+ MOVBU.P R11, 1(R0)
68
+ RORW $8, R3
69
+
70
+ end:
71
+ MOVWU R3, ret+24(FP)
72
+ RET
@@ -0,0 +1,26 @@
1
+ //go:build amd64 || arm64
2
+
3
+ package websocket
4
+
5
+ func mask(b []byte, key uint32) uint32 {
6
+ // TODO: Will enable in v1.9.0.
7
+ return maskGo(b, key)
8
+ /*
9
+ if len(b) > 0 {
10
+ return maskAsm(&b[0], len(b), key)
11
+ }
12
+ return key
13
+ */
14
+ }
15
+
16
+ // @nhooyr: I am not confident that the amd64 or the arm64 implementations of this
17
+ // function are perfect. There are almost certainly missing optimizations or
18
+ // opportunities for simplification. I'm confident there are no bugs though.
19
+ // For example, the arm64 implementation doesn't align memory like the amd64.
20
+ // Or the amd64 implementation could use AVX512 instead of just AVX2.
21
+ // The AVX2 code I had to disable anyway as it wasn't performing as expected.
22
+ // See https://github.com/nhooyr/websocket/pull/326#issuecomment-1771138049
23
+ //
24
+ //go:noescape
25
+ //lint:ignore U1000 disabled till v1.9.0
26
+ func maskAsm(b *byte, len int, key uint32) uint32
@@ -0,0 +1,7 @@
1
+ //go:build !amd64 && !arm64 && !js
2
+
3
+ package websocket
4
+
5
+ func mask(b []byte, key uint32) uint32 {
6
+ return maskGo(b, key)
7
+ }
@@ -0,0 +1,233 @@
1
+ package websocket
2
+
3
+ import (
4
+ "context"
5
+ "fmt"
6
+ "io"
7
+ "math"
8
+ "net"
9
+ "sync/atomic"
10
+ "time"
11
+ )
12
+
13
+ // NetConn converts a *websocket.Conn into a net.Conn.
14
+ //
15
+ // It's for tunneling arbitrary protocols over WebSockets.
16
+ // Few users of the library will need this but it's tricky to implement
17
+ // correctly and so provided in the library.
18
+ // See https://github.com/nhooyr/websocket/issues/100.
19
+ //
20
+ // Every Write to the net.Conn will correspond to a message write of
21
+ // the given type on *websocket.Conn.
22
+ //
23
+ // The passed ctx bounds the lifetime of the net.Conn. If cancelled,
24
+ // all reads and writes on the net.Conn will be cancelled.
25
+ //
26
+ // If a message is read that is not of the correct type, the connection
27
+ // will be closed with StatusUnsupportedData and an error will be returned.
28
+ //
29
+ // Close will close the *websocket.Conn with StatusNormalClosure.
30
+ //
31
+ // When a deadline is hit and there is an active read or write goroutine, the
32
+ // connection will be closed. This is different from most net.Conn implementations
33
+ // where only the reading/writing goroutines are interrupted but the connection
34
+ // is kept alive.
35
+ //
36
+ // The Addr methods will return the real addresses for connections obtained
37
+ // from websocket.Accept. But for connections obtained from websocket.Dial, a mock net.Addr
38
+ // will be returned that gives "websocket" for Network() and "websocket/unknown-addr" for
39
+ // String(). This is because websocket.Dial only exposes a io.ReadWriteCloser instead of the
40
+ // full net.Conn to us.
41
+ //
42
+ // When running as WASM, the Addr methods will always return the mock address described above.
43
+ //
44
+ // A received StatusNormalClosure or StatusGoingAway close frame will be translated to
45
+ // io.EOF when reading.
46
+ //
47
+ // Furthermore, the ReadLimit is set to -1 to disable it.
48
+ func NetConn(ctx context.Context, c *Conn, msgType MessageType) net.Conn {
49
+ c.SetReadLimit(-1)
50
+
51
+ nc := &netConn{
52
+ c: c,
53
+ msgType: msgType,
54
+ readMu: newMu(c),
55
+ writeMu: newMu(c),
56
+ }
57
+
58
+ nc.writeCtx, nc.writeCancel = context.WithCancel(ctx)
59
+ nc.readCtx, nc.readCancel = context.WithCancel(ctx)
60
+
61
+ nc.writeTimer = time.AfterFunc(math.MaxInt64, func() {
62
+ if !nc.writeMu.tryLock() {
63
+ // If the lock cannot be acquired, then there is an
64
+ // active write goroutine and so we should cancel the context.
65
+ nc.writeCancel()
66
+ return
67
+ }
68
+ defer nc.writeMu.unlock()
69
+
70
+ // Prevents future writes from writing until the deadline is reset.
71
+ nc.writeExpired.Store(1)
72
+ })
73
+ if !nc.writeTimer.Stop() {
74
+ <-nc.writeTimer.C
75
+ }
76
+
77
+ nc.readTimer = time.AfterFunc(math.MaxInt64, func() {
78
+ if !nc.readMu.tryLock() {
79
+ // If the lock cannot be acquired, then there is an
80
+ // active read goroutine and so we should cancel the context.
81
+ nc.readCancel()
82
+ return
83
+ }
84
+ defer nc.readMu.unlock()
85
+
86
+ // Prevents future reads from reading until the deadline is reset.
87
+ nc.readExpired.Store(1)
88
+ })
89
+ if !nc.readTimer.Stop() {
90
+ <-nc.readTimer.C
91
+ }
92
+
93
+ return nc
94
+ }
95
+
96
+ type netConn struct {
97
+ c *Conn
98
+ msgType MessageType
99
+
100
+ writeTimer *time.Timer
101
+ writeMu *mu
102
+ writeExpired atomic.Int64
103
+ writeCtx context.Context
104
+ writeCancel context.CancelFunc
105
+
106
+ readTimer *time.Timer
107
+ readMu *mu
108
+ readExpired atomic.Int64
109
+ readCtx context.Context
110
+ readCancel context.CancelFunc
111
+ readEOFed bool
112
+ reader io.Reader
113
+ }
114
+
115
+ var _ net.Conn = &netConn{}
116
+
117
+ func (nc *netConn) Close() error {
118
+ nc.writeTimer.Stop()
119
+ nc.writeCancel()
120
+ nc.readTimer.Stop()
121
+ nc.readCancel()
122
+ return nc.c.Close(StatusNormalClosure, "")
123
+ }
124
+
125
+ func (nc *netConn) Write(p []byte) (int, error) {
126
+ nc.writeMu.forceLock()
127
+ defer nc.writeMu.unlock()
128
+
129
+ if nc.writeExpired.Load() == 1 {
130
+ return 0, fmt.Errorf("failed to write: %w", context.DeadlineExceeded)
131
+ }
132
+
133
+ err := nc.c.Write(nc.writeCtx, nc.msgType, p)
134
+ if err != nil {
135
+ return 0, err
136
+ }
137
+ return len(p), nil
138
+ }
139
+
140
+ func (nc *netConn) Read(p []byte) (int, error) {
141
+ nc.readMu.forceLock()
142
+ defer nc.readMu.unlock()
143
+
144
+ for {
145
+ n, err := nc.read(p)
146
+ if err != nil {
147
+ return n, err
148
+ }
149
+ if n == 0 {
150
+ continue
151
+ }
152
+ return n, nil
153
+ }
154
+ }
155
+
156
+ func (nc *netConn) read(p []byte) (int, error) {
157
+ if nc.readExpired.Load() == 1 {
158
+ return 0, fmt.Errorf("failed to read: %w", context.DeadlineExceeded)
159
+ }
160
+
161
+ if nc.readEOFed {
162
+ return 0, io.EOF
163
+ }
164
+
165
+ if nc.reader == nil {
166
+ typ, r, err := nc.c.Reader(nc.readCtx)
167
+ if err != nil {
168
+ switch CloseStatus(err) {
169
+ case StatusNormalClosure, StatusGoingAway:
170
+ nc.readEOFed = true
171
+ return 0, io.EOF
172
+ }
173
+ return 0, err
174
+ }
175
+ if typ != nc.msgType {
176
+ err := fmt.Errorf("unexpected frame type read (expected %v): %v", nc.msgType, typ)
177
+ nc.c.Close(StatusUnsupportedData, err.Error())
178
+ return 0, err
179
+ }
180
+ nc.reader = r
181
+ }
182
+
183
+ n, err := nc.reader.Read(p)
184
+ if err == io.EOF {
185
+ nc.reader = nil
186
+ err = nil
187
+ }
188
+ return n, err
189
+ }
190
+
191
+ type websocketAddr struct{}
192
+
193
+ func (a websocketAddr) Network() string {
194
+ return "websocket"
195
+ }
196
+
197
+ func (a websocketAddr) String() string {
198
+ return "websocket/unknown-addr"
199
+ }
200
+
201
+ func (nc *netConn) SetDeadline(t time.Time) error {
202
+ nc.SetWriteDeadline(t)
203
+ nc.SetReadDeadline(t)
204
+ return nil
205
+ }
206
+
207
+ func (nc *netConn) SetWriteDeadline(t time.Time) error {
208
+ nc.writeExpired.Store(0)
209
+ if t.IsZero() {
210
+ nc.writeTimer.Stop()
211
+ } else {
212
+ dur := time.Until(t)
213
+ if dur <= 0 {
214
+ dur = 1
215
+ }
216
+ nc.writeTimer.Reset(dur)
217
+ }
218
+ return nil
219
+ }
220
+
221
+ func (nc *netConn) SetReadDeadline(t time.Time) error {
222
+ nc.readExpired.Store(0)
223
+ if t.IsZero() {
224
+ nc.readTimer.Stop()
225
+ } else {
226
+ dur := time.Until(t)
227
+ if dur <= 0 {
228
+ dur = 1
229
+ }
230
+ nc.readTimer.Reset(dur)
231
+ }
232
+ return nil
233
+ }
@@ -0,0 +1,11 @@
1
+ package websocket
2
+
3
+ import "net"
4
+
5
+ func (nc *netConn) RemoteAddr() net.Addr {
6
+ return websocketAddr{}
7
+ }
8
+
9
+ func (nc *netConn) LocalAddr() net.Addr {
10
+ return websocketAddr{}
11
+ }
@@ -0,0 +1,19 @@
1
+ //go:build !js
2
+
3
+ package websocket
4
+
5
+ import "net"
6
+
7
+ func (nc *netConn) RemoteAddr() net.Addr {
8
+ if unc, ok := nc.c.rwc.(net.Conn); ok {
9
+ return unc.RemoteAddr()
10
+ }
11
+ return websocketAddr{}
12
+ }
13
+
14
+ func (nc *netConn) LocalAddr() net.Addr {
15
+ if unc, ok := nc.c.rwc.(net.Conn); ok {
16
+ return unc.LocalAddr()
17
+ }
18
+ return websocketAddr{}
19
+ }