From 7299d63711a10f6784c52e7e70a5978c3238954c Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Mon, 10 Apr 2023 10:07:52 -0700 Subject: [PATCH] fixing create permission handling --- app/mobile/src/context/useRingContext.hook.js | 5 +++- net/server/internal/sturn/message.go | 27 ++++++++++++++++--- net/server/internal/sturn/types.go | 6 +++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/app/mobile/src/context/useRingContext.hook.js b/app/mobile/src/context/useRingContext.hook.js index 8f5f95d4..4f2426d0 100644 --- a/app/mobile/src/context/useRingContext.hook.js +++ b/app/mobile/src/context/useRingContext.hook.js @@ -241,6 +241,7 @@ export function useRingContext() { // connect signal socket connected.current = false; candidates.current = []; + pc.current = null; updateState({ remoteVideo: false, remoteAudio: false, remoteStream: null, localVideo: false, localAudio: false, localStream: null }); videoTrack.current = false; @@ -288,7 +289,9 @@ export function useRingContext() { } ws.current.onclose = (e) => { // update state to disconnected - pc.current.close(); + if (pc.current) { + pc.current.close(); + } clearRing(); clearAlive(); calling.current = null; diff --git a/net/server/internal/sturn/message.go b/net/server/internal/sturn/message.go index 5a5196cc..77e3aed3 100644 --- a/net/server/internal/sturn/message.go +++ b/net/server/internal/sturn/message.go @@ -120,11 +120,31 @@ func (s *Sturn) handleMessage(buf []byte, addr net.Addr) { } func (s *Sturn) handleCreatePermissionRequest(msg *SturnMessage, addr net.Addr) { - fmt.Println(addr.String(), msg); +fmt.Println(addr.String(), msg); + + var attributes []SturnAttribute + attributes = append(attributes, SturnAttribute{ + atrType: ATRMessageIntegrity, + }); + + response := &SturnMessage{ + class: CLSResponse, + method: MEHCreatePermission, + transaction: msg.transaction, + attributes: attributes, + }; + err, n := writeMessage(response, s.buf); + if err != nil { + fmt.Printf("failed to write stun response"); + } else { + (*s.conn).WriteTo(s.buf[:n], addr); +fmt.Println("PERM>", s.buf[:n]); + } + return } func (s *Sturn) handleSendIndication(msg *SturnMessage, addr net.Addr) { - fmt.Println(addr.String(), msg); + //fmt.Println(addr.String(), msg); } func (s *Sturn) handleBindingRequest(msg *SturnMessage, addr net.Addr) { @@ -222,7 +242,8 @@ func (s *Sturn) handleAllocateRequest(msg *SturnMessage, addr net.Addr) { atrType: ATRXorRelayedAddress, byteValue: FAMIPv4, intValue: int32(relayPort), - strValue: "98.234.232.221", + strValue: "192.168.13.233", + //strValue: "98.234.232.221", }); attributes = append(attributes, SturnAttribute{ atrType: ATRLifetime, diff --git a/net/server/internal/sturn/types.go b/net/server/internal/sturn/types.go index 2dde4964..a1fbc0e0 100644 --- a/net/server/internal/sturn/types.go +++ b/net/server/internal/sturn/types.go @@ -138,6 +138,12 @@ func setMessageType(class int, method int) (byte, byte) { if class == CLSError && method == MEHAllocate { return 0x01, 0x13 } + if class == CLSResponse && method == MEHCreatePermission { + return 0x01, 0x08 + } + if class == CLSError && method == MEHCreatePermission { + return 0x01, 0x18 + } return 0x00, 0x00 }