mirror of
https://github.com/balzack/databag.git
synced 2025-04-20 16:45:25 +00:00
preparing to send data over relay
This commit is contained in:
parent
ef7c5f9d9b
commit
e2b33bccfe
@ -38,13 +38,32 @@ func readAttribute(buf []byte, pos int) (error, *SturnAttribute, int) {
|
||||
} else if atrType == ATRRealm {
|
||||
strValue = string(buf[pos + 4:pos + 4+atrLength]);
|
||||
} else if atrType == ATRMessageIntegrity {
|
||||
fmt.Println("HANDLE: ATRMessageIntegrity");
|
||||
//fmt.Println("HANDLE: ATRMessageIntegrity");
|
||||
} else if atrType == ATRMessageIntegritySha256 {
|
||||
fmt.Println("HANDLE: ATRMessageIntegritySha256");
|
||||
//fmt.Println("HANDLE: ATRMessageIntegritySha256");
|
||||
} else if atrType == ATRFingerprint {
|
||||
fmt.Println("HANDLE: ATRFingerprint");
|
||||
//fmt.Println("HANDLE: ATRFingerprint");
|
||||
} else if atrType == ATRXorPeerAddress {
|
||||
if padLength != 8 {
|
||||
return errors.New("invalid attribute size"), nil, 0
|
||||
}
|
||||
if buf[pos + 4] != 0 || buf[pos + 5] != FAMIPv4 {
|
||||
return errors.New("unsupported protocol family"), nil, 0
|
||||
}
|
||||
strValue = ""
|
||||
strValue += strconv.Itoa(int(buf[pos + 8] ^ 0x21))
|
||||
strValue += "."
|
||||
strValue += strconv.Itoa(int(buf[pos + 9] ^ 0x12))
|
||||
strValue += "."
|
||||
strValue += strconv.Itoa(int(buf[pos + 10] ^ 0xA4))
|
||||
strValue += "."
|
||||
strValue += strconv.Itoa(int(buf[pos + 11] ^ 0x42))
|
||||
intValue = int32(buf[pos + 6] ^ 0x21)
|
||||
intValue *= 256
|
||||
intValue += int32(buf[pos + 7] ^ 0x12)
|
||||
} else if atrType == ATRData {
|
||||
} else {
|
||||
fmt.Println("UNKNOWN ATTRIBUTE");
|
||||
fmt.Println("UNKNOWN ATTRIBUTE", atrType);
|
||||
}
|
||||
|
||||
return nil, &SturnAttribute{
|
||||
|
@ -51,6 +51,7 @@ func writeMessage(msg *SturnMessage, buf []byte) (error, int) {
|
||||
if len(buf) < 20 {
|
||||
return errors.New("invalid buffer length"), 0
|
||||
}
|
||||
|
||||
// set prefix
|
||||
buf[0], buf[1] = setMessageType(msg.class, msg.method)
|
||||
|
||||
@ -90,6 +91,7 @@ func (s *Sturn) handleMessage(buf []byte, addr net.Addr) {
|
||||
|
||||
err, msg := readMessage(buf);
|
||||
if err != nil {
|
||||
fmt.Println(addr.String(), buf);
|
||||
fmt.Println(err);
|
||||
return
|
||||
}
|
||||
@ -98,14 +100,33 @@ func (s *Sturn) handleMessage(buf []byte, addr net.Addr) {
|
||||
}
|
||||
|
||||
if msg.class == CLSRequest && msg.method == MEHBinding {
|
||||
fmt.Println("stun/turn binding request");
|
||||
s.handleBindingRequest(msg, addr);
|
||||
} else if msg.class == CLSRequest && msg.method == MEHAllocate {
|
||||
fmt.Println("stun/turn allocate request");
|
||||
s.handleAllocateRequest(msg, addr);
|
||||
} else if msg.class == CLSRequest && msg.method == MEHRefresh {
|
||||
fmt.Println("stun/turn refresh request");
|
||||
s.handleRefreshRequest(msg, addr);
|
||||
} else if msg.class == CLSRequest && msg.method == MEHCreatePermission {
|
||||
fmt.Println("stun/turn create permission request");
|
||||
s.handleCreatePermissionRequest(msg, addr);
|
||||
} else if msg.class == CLSIndication && msg.method == MEHSend {
|
||||
fmt.Println("stun/turn send");
|
||||
s.handleSendIndication(msg, addr);
|
||||
} else {
|
||||
fmt.Println("unsupported message", buf);
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Sturn) handleCreatePermissionRequest(msg *SturnMessage, addr net.Addr) {
|
||||
fmt.Println(addr.String(), msg);
|
||||
}
|
||||
|
||||
func (s *Sturn) handleSendIndication(msg *SturnMessage, addr net.Addr) {
|
||||
fmt.Println(addr.String(), msg);
|
||||
}
|
||||
|
||||
func (s *Sturn) handleBindingRequest(msg *SturnMessage, addr net.Addr) {
|
||||
|
||||
address := strings.Split(addr.String(), ":")
|
||||
@ -133,6 +154,23 @@ func (s *Sturn) handleBindingRequest(msg *SturnMessage, addr net.Addr) {
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Sturn) handleRefreshRequest(msg *SturnMessage, addr net.Addr) {
|
||||
|
||||
response := &SturnMessage{
|
||||
class: CLSResponse,
|
||||
method: MEHRefresh,
|
||||
transaction: msg.transaction,
|
||||
attributes: []SturnAttribute{},
|
||||
};
|
||||
err, n := writeMessage(response, s.buf);
|
||||
if err != nil {
|
||||
fmt.Printf("failed to write stun response");
|
||||
} else {
|
||||
(*s.conn).WriteTo(s.buf[:n], addr);
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *Sturn) sendAllocateError(msg *SturnMessage, addr net.Addr) {
|
||||
var attributes []SturnAttribute
|
||||
attributes = append(attributes, SturnAttribute{
|
||||
@ -179,14 +217,12 @@ func (s *Sturn) handleAllocateRequest(msg *SturnMessage, addr net.Addr) {
|
||||
address := strings.Split(addr.String(), ":")
|
||||
ip := address[0];
|
||||
port, _ := strconv.Atoi(address[1]);
|
||||
//port := 53046
|
||||
var attributes []SturnAttribute
|
||||
attributes = append(attributes, SturnAttribute{
|
||||
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,
|
||||
|
@ -203,6 +203,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;
|
||||
@ -252,7 +253,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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user