khoanguyen-3fc / dh-p2p

A proof of concept implementation of RTSP over Dahua P2P protocol.
MIT License
27 stars 13 forks source link

Help is needed #3

Closed darkobg79 closed 9 months ago

darkobg79 commented 11 months ago

Greeting. The project is fantastic, congratulations.

I need help. I have an idea that I want to implement, but I can't.

In short, I want to run a service on one server (OS) that will create a VPN to Dahua servers and enable RTSP.

From the second computer, I want to access the IP address of the first computer and watch the stream created in this way.

I manage connect and the system creates a VPN. However, I can't watch the stream at all.


HTTP/1.1 200 Server Nat Info!
CSeq: 5
Content-Type:
Content-Length: 259

<body><Identify>8a 77 c6 8d b5 fe e6 58</Identify><IpEncrpt>false</IpEncrpt><LocalAddr>192.168.1.110:45660</LocalAddr><NatValueT>1</NatValueT><Policy>p2p,udprelay</Policy><PubAddr>212.200.247.162:15634</PubAddr><Relay>:0</Relay><version>6.0.0</version></body>
---
DHResponse { version: "HTTP/1.1", code: 200, status: "Server", headers: {"CSeq": "5", "Content-Type": "", "Content-Length": "259"}, body: Some({"body/Relay": ":0", "body/Policy": "p2p,udprelay", "body/IpEncrpt": "false", "body/LocalAddr": "192.168.1.110:45660", "body/PubAddr": "212.200.247.162:15634", "body/version": "6.0.0", "body/Identify": "8a 77 c6 8d b5 fe e6 58", "body/NatValueT": "1"}) }
>>> 128.14.224.146:8800
DHPOST /device/XXXXXXXX/relay-channel HTTP/1.1
CSeq: 8
Authorization: WSSE profile="UsernameToken"
X-WSSE: UsernameToken Username="P2PClient", PasswordDigest="UbOt/zqNAoDhkxOmhiK/H84YaSc=", Nonce="1390900817", Created="2023-12-16T17:52:05Z"

<body><agentAddr>148.153.240.198:41617</agentAddr></body>
---
<<< 148.153.240.198:41617
HTTP/1.1 200 Server Nat Info!
CSeq: 8
Content-Type:
Content-Length: 37

<body><version>6.0.0</version></body>
---
DHResponse { version: "HTTP/1.1", code: 200, status: "Server", headers: {"Content-Type": "", "CSeq": "8", "Content-Length": "37"}, body: Some({"body/version": "6.0.0"}) }
>>> 148.153.240.198:41617
PTCPPacket { sent: 0, recv: 0, pid: 0x0002ffff, lmid: 0x00000000, rmid: 0x00000000, body: Command([00 03 01 00]) }
---
<<< 148.153.240.198:41617
PTCPPacket { sent: 0, recv: 4, pid: 0x0002ffff, lmid: 0x01800b28, rmid: 0x00000000, body: Command([00 03 01 00]) }
---
>>> 148.153.240.198:41617
PTCPPacket { sent: 4, recv: 4, pid: 0x0000ffff, lmid: 0x00000001, rmid: 0x01800b28, body: Command([17 00 00 00 00 00 00 00 00 00 00 00]) }
---
<<< 148.153.240.198:41617
PTCPPacket { sent: 4, recv: 16, pid: 0x0000fff3, lmid: 0x01800b82, rmid: 0x00000001, body: Empty }
---
<<< 148.153.240.198:41617
PTCPPacket { sent: 4, recv: 16, pid: 0x0000fff3, lmid: 0x01800b82, rmid: 0x00000001, body: Command([18 00 00 00 00 00 00 00 00 00 00 00 00 4e 5f fb]) }
---
Sign: 004e5ffb
>>> 212.200.247.162:15634
Raw [ff fe ff e7 de ed 5b bd b3 03 ef 13 41 2b 12 ae f9 ba b2 66 7f d5 ff f7 2b 61 98 57 d4 2b 81 e1 ff fb ff f7 ff fe a8 13 21 02 d2 65]
---
<<< 212.200.247.162:15634
khoanguyen-3fc commented 11 months ago

It's great that you've explored the enhanced Rust implementation, and it seems our scenarios align.

Regarding the issue you're facing, please note that the tunnel is still in the process of establishing until you see the "Ready to connect!" message in the log.

Have you tried aborting and retrying the process multiple times? I've noticed my PoC still occasionally hangs in the middle of establishing, so this might be worth exploring.

darkobg79 commented 11 months ago

I never seen message "Ready to connect"... I will try again.

darkobg79 commented 11 months ago

As far as I can see, the last step does not pass: P2P handshake

darkobg79 commented 11 months ago

Can you try: 4L0A4AAPBQCAC1B ?

khoanguyen-3fc commented 11 months ago

I've checked and found that, for some reason, a direct connection to your device isn't possible. Instead, it has to use relay mode, which is not yet supported.

darkobg79 commented 11 months ago

Is there a plan to implement and support relay mode in next period? :)

khoanguyen-3fc commented 11 months ago

I've drafted an experimental relay mode in the feature/relay branch. You might want to give it a try.

Keep in mind that it's currently an experimental feature as part of a proof of concept, so more effort and help are needed to finalize it.

darkobg79 commented 11 months ago

It not working... I don't see Ready to connect...

>>> 128.14.225.236:8800
DHGET /probe/p2psrv HTTP/1.1
CSeq: 1
Authorization: WSSE profile="UsernameToken"
X-WSSE: UsernameToken Username="P2PClient", PasswordDigest="HvAqydeFx9pTgUKR4cSMJaoeCiQ=", Nonce="4256704150", Created="2023-12-18T19:19:43Z"

---
<<< 128.14.225.236:8800
HTTP/1.1 200 OK
Date: 2023-12-18T19:19:43Z
CSeq: 1

---
DHResponse { version: "HTTP/1.1", code: 200, status: "OK", headers: {"Date": "2023-12-18T19:19:43Z", "CSeq": "1"}, body: None }
>>> 128.14.225.236:8800
DHGET /online/p2psrv/4L0A4AAPBQCAC1B HTTP/1.1
CSeq: 2
Authorization: WSSE profile="UsernameToken"
X-WSSE: UsernameToken Username="P2PClient", PasswordDigest="xkGJHLPPwJQCY+PhcrYIeeUvXuo=", Nonce="3957376089", Created="2023-12-18T19:19:43Z"

---
<<< 128.14.225.236:8800
HTTP/1.1 200 OK
Date: 2023-12-18T19:19:43Z
CSeq: 2
Content-Type:
Content-Length: 65

<body><DS>45.43.62.214:8802</DS><US>45.43.62.214:8803</US></body>
---
DHResponse { version: "HTTP/1.1", code: 200, status: "OK", headers: {"CSeq": "2", "Date": "2023-12-18T19:19:43Z", "Content-Length": "65", "Content-Type": ""}, body: Some({"body/US": "45.43.62.214:8803", "body/DS": "45.43.62.214:8802"}) }
>>> 128.14.225.236:8800
DHGET /online/relay HTTP/1.1
CSeq: 3
Authorization: WSSE profile="UsernameToken"
X-WSSE: UsernameToken Username="P2PClient", PasswordDigest="kWJZIZ4DEaC5eZOAQW8cD5RErhM=", Nonce="2271209796", Created="2023-12-18T19:19:43Z"

---
<<< 128.14.225.236:8800
HTTP/1.1 200 OK
Date: 2023-12-18T19:19:43Z
CSeq: 3
Content-Type:
Content-Length: 89

<?xml version="1.0" encoding="UTF-8"?><body><Address>165.154.165.20:8900</Address></body>
---
DHResponse { version: "HTTP/1.1", code: 200, status: "OK", headers: {"Content-Type": "", "CSeq": "3", "Date": "2023-12-18T19:19:43Z", "Content-Length": "89"}, body: Some({"body/Address": "165.154.165.20:8900"}) }
>>> 45.43.62.214:8803
DHGET /probe/device/4L0A4AAPBQCAC1B HTTP/1.1
CSeq: 4
Authorization: WSSE profile="UsernameToken"
X-WSSE: UsernameToken Username="P2PClient", PasswordDigest="jkMGbK6GMIYWG7P9+MPZ41T4Tbw=", Nonce="98697944", Created="2023-12-18T19:19:44Z"

---
<<< 45.43.62.214:8803
HTTP/1.1 200 OK
CSeq: 4
Date: 2023-12-18T19:19:44Z

---
DHResponse { version: "HTTP/1.1", code: 200, status: "OK", headers: {"Date": "2023-12-18T19:19:44Z", "CSeq": "4"}, body: None }
>>> 128.14.225.236:8800
DHPOST /device/4L0A4AAPBQCAC1B/p2p-channel HTTP/1.1
CSeq: 5
Authorization: WSSE profile="UsernameToken"
X-WSSE: UsernameToken Username="P2PClient", PasswordDigest="qXKYKoQniDC978eRh5hj3a3w9UU=", Nonce="269949292", Created="2023-12-18T19:19:44Z"

<body><Identify>d4 9e 67 a8 2b d4 7e 1e</Identify><IpEncrpt>true</IpEncrpt><LocalAddr>63.87.143.254,63.87.254.173:54329</LocalAddr><version>5.0.0</version></body>
---
>>> 165.154.165.20:8900
DHGET /relay/agent HTTP/1.1
CSeq: 6
Authorization: WSSE profile="UsernameToken"
X-WSSE: UsernameToken Username="P2PClient", PasswordDigest="Fli3oPJzQcNsdorbeAoXLV+PiI8=", Nonce="1520506469", Created="2023-12-18T19:19:44Z"

---
<<< 165.154.165.20:8900
HTTP/1.1 200 OK
CSeq: 6
Content-Type:
Content-Length: 170

<?xml version="1.0" encoding="UTF-8"?><body><Agent>165.154.165.33:48812</Agent><Token>C181A0DFF944F8D4D1BF8AF6D3903344-35c55f3da353e4cde075aae301969f96</Token></body>

---
DHResponse { version: "HTTP/1.1", code: 200, status: "OK", headers: {"Content-Type": "", "CSeq": "6", "Content-Length": "170"}, body: Some({"body/Token": "C181A0DFF944F8D4D1BF8AF6D3903344-35c55f3da353e4cde075aae301969f96", "body/Agent": "165.154.165.33:48812"}) }
>>> 165.154.165.33:48812
DHPOST /relay/start/C181A0DFF944F8D4D1BF8AF6D3903344-35c55f3da353e4cde075aae301969f96 HTTP/1.1
CSeq: 7
Authorization: WSSE profile="UsernameToken"
X-WSSE: UsernameToken Username="P2PClient", PasswordDigest="NZ2DFHfw1+3NHatMoCIAF0bBrmw=", Nonce="2072165190", Created="2023-12-18T19:19:44Z"

<body><Client>:0</Client></body>
---
<<< 165.154.165.33:48812
HTTP/1.1 200 OK
CSeq: 7
Content-Type:
Content-Length: 113

<?xml version="1.0" encoding="UTF-8"?><body><SID>35c55f3da353e4cde075aae301969f96</SID><Time>30</Time></body>

---
DHResponse { version: "HTTP/1.1", code: 200, status: "OK", headers: {"Content-Length": "113", "CSeq": "7", "Content-Type": ""}, body: Some({"body/Time": "30", "body/SID": "35c55f3da353e4cde075aae301969f96"}) }
<<< 128.14.225.236:8800
HTTP/1.1 100 Trying
CSeq: 5
Content-Type:
Content-Length: 13

<body></body>
---
DHResponse { version: "HTTP/1.1", code: 100, status: "Trying", headers: {"Content-Type": "", "Content-Length": "13", "CSeq": "5"}, body: Some({}) }
<<< 128.14.225.236:8800
HTTP/1.1 200 Server Nat Info!
CSeq: 5
Content-Type:
Content-Length: 257

<body><Identify>4e 37 74 f8 57 d2 7a d2</Identify><IpEncrpt>false</IpEncrpt><LocalAddr>192.168.1.110:46007</LocalAddr><NatValueT>1</NatValueT><Policy>p2p,udprelay</Policy><PubAddr>212.200.65.84:21411</PubAddr><Relay>:0</Relay><version>6.0.0</version></body>
---
DHResponse { version: "HTTP/1.1", code: 200, status: "Server", headers: {"CSeq": "5", "Content-Length": "257", "Content-Type": ""}, body: Some({"body/IpEncrpt": "false", "body/PubAddr": "212.200.65.84:21411", "body/Relay": ":0", "body/Policy": "p2p,udprelay", "body/Identify": "4e 37 74 f8 57 d2 7a d2", "body/version": "6.0.0", "body/NatValueT": "1", "body/LocalAddr": "192.168.1.110:46007"}) }
>>> 128.1.34.21:8800
DHPOST /device/4L0A4AAPBQCAC1B/relay-channel HTTP/1.1
CSeq: 8
Authorization: WSSE profile="UsernameToken"
X-WSSE: UsernameToken Username="P2PClient", PasswordDigest="mxHBALLG/eJS2FoeA3Z0zsRy8to=", Nonce="3100204804", Created="2023-12-18T19:19:44Z"

<body><agentAddr>165.154.165.33:48812</agentAddr></body>
---
<<< 165.154.165.33:48812
HTTP/1.1 200 Server Nat Info!
CSeq: 8
Content-Type:
Content-Length: 37

<body><version>6.0.0</version></body>
---
DHResponse { version: "HTTP/1.1", code: 200, status: "Server", headers: {"Content-Length": "37", "CSeq": "8", "Content-Type": ""}, body: Some({"body/version": "6.0.0"}) }
>>> 165.154.165.33:48812
PTCPPacket { sent: 0, recv: 0, pid: 0x0002ffff, lmid: 0x00000000, rmid: 0x00000000, body: Command([00 03 01 00]) }
---
<<< 165.154.165.33:48812
PTCPPacket { sent: 0, recv: 4, pid: 0x0002ffff, lmid: 0x086b44a2, rmid: 0x00000000, body: Command([00 03 01 00]) }
---
>>> 165.154.165.33:48812
PTCPPacket { sent: 4, recv: 4, pid: 0x0000ffff, lmid: 0x00000001, rmid: 0x086b44a2, body: Command([17 00 00 00 00 00 00 00 00 00 00 00]) }
---
<<< 165.154.165.33:48812
PTCPPacket { sent: 4, recv: 16, pid: 0x0000fff3, lmid: 0x086b4506, rmid: 0x00000001, body: Empty }
---
<<< 165.154.165.33:48812
PTCPPacket { sent: 4, recv: 16, pid: 0x0000fff3, lmid: 0x086b4510, rmid: 0x00000001, body: Command([18 00 00 00 00 00 00 00 00 00 00 00 43 fa bf ff]) }
---
Sign: 43fabfff
>>> 212.200.65.84:21411
Raw [ff fe ff e7 de ed 5b bd b3 03 ef 13 41 2b 12 ae f9 ba b2 66 7f d5 ff f7 2b 61 98 57 d4 2b 81 e1 ff fb ff f7 ff fe a8 13 21 02 d2 65]
---
<<< 212.200.65.84:21411
khoanguyen-3fc commented 11 months ago

Did you specify -r / --relay option?

darkobg79 commented 11 months ago

You are a genius 🥇 👍

p2p-sys commented 11 months ago

Can you repeat this in a Python3 program?

khoanguyen-3fc commented 11 months ago

@darkobg79 I haven't successfully tested it yet. I'm only able to see half of the first frame, possibly because Easy4IPCloud Agent detects that my device can connect directly and stops relaying.

@p2p-sys I gave it a quick try, but unfortunately, it failed. The polling and non-async architecture of my Python script make it less flexible. Moving forward, I'll be focusing exclusively on Rust development, keeping the Python one only as a reference.

darkobg79 commented 11 months ago

@khoanguyen-3fc How can I send you the account to test? I can't create a temporary account, this is a shared account that we use.

khoanguyen-3fc commented 11 months ago

@darkobg79 For now, I won't need a testing account if you can confirm that this feature is working.

Can you provide more details on its reliability? Does it work consistently, run smoothly, and how long can you watch without issues? These issues may be related to the overall protocol finalizing that I'm working on, not specific to relay.

darkobg79 commented 10 months ago

@khoanguyen-3fc After the new changes, everything is much more stable. Before the changes, everything worked for up to one minute. Now I tested it only once, it works for about 5-6 minutes and then stops.

### 47.246.43.231:46937
Reader: Socket closed by peer.
>>> 47.246.43.231:46937
PTCPPacket { sent: 52985, recv: 326696788, pid: 0x0000ff66, lmid: 0x0003e6f8, rmid: 0x0565519e, body: length: 377, realm: 0xbce4efc8, data: [54 45 41 52 44 4f 57 4e 20 72 74 73 70 3a 2f 2f ...] }
TEARDOWN rtsp://192.168.0.13:1554/cam/realmonitor?channel=5&subtype=1/ RTSP/1.0
CSeq: 19
User-Agent: Lavf59.27.100

Realm 57524491 unavailable
### 47.246.43.231:46937
<<< 47.246.43.231:46937
PTCPPacket { sent: 326813392, recv: 52985, pid: 0x0000f9d7, lmid: 0x05659dd4, rmid: 0x0003cfad, body: length: 1280, realm: 0x6573b04f, data: [49 b0 67 42 27 49 01 b8 7d a0 04 8d 47 b8 34 e4 ...] }
---
github-actions[bot] commented 9 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 9 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale.