eclipse / paho.mqtt-sn.embedded-c

Paho C MQTT-SN gateway and libraries for embedded systems. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
314 stars 178 forks source link

dtls branch has bugs. #241

Closed ty4tw closed 3 years ago

ty4tw commented 3 years ago

Client can't reconnect.

┌tomoaki@valtan:~/tmp/paho.mqtt-sn.embedded-c/MQTTSNGateway/GatewayTester/Build
└─▶ ./MQTT-SNGatewayTester0

 ***************************************************************************
 * MQTT-SN Gateway Tester   DTLS ClientId:GatewayTestClient001 PortNo:30030
 * Part of Project Paho in Eclipse
 * (http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt-sn.embedded-c.git/)
 *
 * Author : Tomoaki YAMAGUCHI
 * Version: 2.0.0
 ***************************************************************************
Attempting to Connect the Broker.....

**** Step0:Connect start ****

sendto 225.1.1.1      :1883   03 01 00
Mcast recved 172.16.1.11    :1883   03 01 00
recved 172.16.1.11    :1883   03 01 00
  recv SEARCHGW
Mcast recved 172.16.1.11    :10000  03 02 01
recved 172.16.1.11    :10000  03 02 01
  recv GWINFO
LDtlsPort::sslConnect connect to 172.16.1.11    :10000 
SSL connected
sendto gateway via DTLS  1a 04 04 01 00 3c 47 61 74 65 77 61 79 54 65 73 74 43 6c 69 65 6e 74 30 30 31
sendto the gateway via SSL   1a 04 04 01 00 3c 47 61 74 65 77 61 79 54 65 73 74 43 6c 69 65 6e 74 30 30 31
  send CONNECT
  recv CONNACK

 Connected to the Broker

**** Step0:Connect complete ****

Execute "Step1:Subscribe list" ? ( y/n ) : ^C

Enter ctrl+C to stop the client Start Client to reconnect.

 ***************************************************************************
 * MQTT-SN Gateway Tester   DTLS ClientId:GatewayTestClient001 PortNo:30030
 * Part of Project Paho in Eclipse
 * (http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt-sn.embedded-c.git/)
 *
 * Author : Tomoaki YAMAGUCHI
 * Version: 2.0.0
 ***************************************************************************
Attempting to Connect the Broker.....

**** Step0:Connect start ****

sendto 225.1.1.1      :1883   03 01 00
Mcast recved 172.16.1.11    :1883   03 01 00
recved 172.16.1.11    :1883   03 01 00
  recv SEARCHGW
Mcast recved 172.16.1.11    :10000  03 02 01
recved 172.16.1.11    :10000  03 02 01
  recv GWINFO
LDtlsPort::sslConnect connect to 172.16.1.11    :10000

SSL_connect() blocks

Gateway Log is as follows:

 ***************************************************************************
 * 
 * Part of Project Paho in Eclipse
 * (http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt-sn.embedded-c.git/)
 *
 * Author : Tomoaki YAMAGUCHI
 * Version: 1.6.0
 ***************************************************************************
 ConfigFile  : /home/tomoaki/workspace-MQTT-SN/paho.mqtt-sn.embedded-c/MQTTSNGateway/gateway.conf
 ClientList  : /path/to/your_clients.conf
 Broker      : mqtt.eclipseprojects.io : 1883, 8883
 RootCApath  : (null)
 RootCAfile  : (null)
 CertKey     : (null)
 PrivateKey  : (null)
 SensorN/W   : IPv4 DTLS Multicast 225.1.1.1:1883, Gateway PortNo:10000, TTL:1
 DtlsCertsKey: /etc/ssl/certs/gateway.pem
 DtlsPrivKey : /etc/ssl/private/privkey.pem
 Max Clients : 30

20210802 112543.237 PahoGateway-01 starts running.

IPv4 multicast recved from 172.16.1.11:1883 length = 3

20210802 112549.509   SEARCHGW          <---  Client                              03 01 00
20210802 112549.510   GWINFO            --->  Clients                             03 02 01
sendto 225.1.1.1:1883 length = 3
IPv4 multicast recved from 172.16.1.11:10000 length = 3
Connect RECV
SensorNetwork::getSenderAddress recved from 172.16.1.11:30030 length = 15
getSenderAddress len=15  Packet type=22
Listen SSL
Client 172.16.1.11:30030 SSL Accepted. idx=0
SSL RECV
SensorNetwork::getSenderAddress recved from 172.16.1.11:30030 length = 15
getSenderAddress len=15  Packet type=23
DTLT type=10001
Client 172.16.1.11:0 SSL Accepted. idx=0

20210802 112549.519   CONNECT           <---  GatewayTestClient001                1A 04 04 01 00 3C 47 61 74 65 77 61 79 54 65 73 74 43 6C 69 65 6E 74 30 30 31
20210802 112549.770   CONNECT           ===>  GatewayTestClient001                10 20 00 04 4D 51 54 54 04 02 00 3C 00 14 47 61 74 65 77 61 79 54 65 73 74 43 6C 69 65 6E 74 30 30 31
20210802 112550.241   CONNACK           <===  GatewayTestClient001                20 02 00 00
20210802 112550.241   CONNACK           --->  GatewayTestClient001                03 05 00

CLIENT CONNECT ONCE HERE!

IPv4 multicast recved from 172.16.1.11:1883 length = 3

20210802 112556.804   SEARCHGW          <---  Client                              03 01 00
20210802 112556.805   GWINFO            --->  Clients                             03 02 01
sendto 225.1.1.1:1883 length = 3
IPv4 multicast recved from 172.16.1.11:10000 length = 3
SSL RECV
SensorNetwork::getSenderAddress recved from 172.16.1.11:30030 length = 15
getSenderAddress len=15  Packet type=22
DTLT type=10000
Client 172.16.1.11:0 SSL reconnect. idx=0
Listen SSL
ty4tw commented 3 years ago

In case of one client works fine. When one more client try to CONNECT, SSL_connection was established and client can't receive CONNACK. Gateway returns CONNACK to the first client.
Gateway's log is as follows:

Client 172.16.1.11:30030 SSL Accepted. idx=0
SSL RECV
SensorNetwork::getSenderAddress recved from 172.16.1.11:30030 length = 15
Client 172.16.1.11:0 SSL Accepted. idx=0

ClientId of 172.16.1.11:30030 is GatewayTestClient30030.

20210802 175743.512   CONNECT           <---  GatewayTestClient30030             
20210802 175743.908   CONNECT           ===>  GatewayTestClient30030              
20210802 175744.373   CONNACK           <===  GatewayTestClient30030             
20210802 175744.373   CONNACK           --->  GatewayTestClient30030           
IPv4 multicast recved from 172.16.1.11:1883 length = 3

20210802 175813.822   SEARCHGW          <---  Client                          
20210802 175813.822   GWINFO            --->  Clients                         
sendto 225.1.1.1:1883 length = 3
IPv4 multicast recved from 172.16.1.11:10000 length = 3
Connect RECV
SensorNetwork::getSenderAddress recved from 172.16.1.11:20020 length = 15
Listen SSL
Client 172.16.1.11:20020 SSL Accepted. idx=1
SSL RECV
SensorNetwork::getSenderAddress recved from 172.16.1.11:20020 length = 15
Client 172.16.1.11:0 SSL Accepted. idx=1

Client Id of 172.16.1.11:20020 should be GatewayTestClient20020. but 30030

20210802 175813.827   CONNECT           <---  GatewayTestClient30030              
20210802 175813.989   CONNECT           ===>  GatewayTestClient30030              
20210802 175814.408   CONNACK           <===  GatewayTestClient30030              
20210802 175814.409   CONNACK           --->  GatewayTestClient30030 
ty4tw commented 3 years ago

DTLS over IPv6 is not debugged.