Skip to content

Commit

Permalink
[rendezvous] Add initial support for IP rendezvous
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing committed Nov 6, 2020
1 parent 4f757f7 commit 35d58d5
Show file tree
Hide file tree
Showing 34 changed files with 738 additions and 261 deletions.
26 changes: 15 additions & 11 deletions examples/all-clusters-app/esp32/main/EchoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <support/ErrorStr.h>
#include <system/SystemPacketBuffer.h>
#include <transport/SecureSessionMgr.h>
#include <transport/TransportMgr.h>
#include <transport/raw/Tuple.h>
#include <transport/raw/UDP.h>

Expand Down Expand Up @@ -122,7 +123,7 @@ class EchoServerCallback : public SecureSessionMgrDelegate
{
public:
void OnMessageReceived(const PacketHeader & header, const PayloadHeader & payloadHeader, Transport::PeerConnectionState * state,
System::PacketBuffer * buffer, SecureSessionMgrBase * mgr) override
System::PacketBuffer * buffer, SecureSessionMgr * mgr) override
{
CHIP_ERROR err;
const size_t data_len = buffer->DataLength();
Expand Down Expand Up @@ -179,13 +180,13 @@ class EchoServerCallback : public SecureSessionMgrDelegate
}
}

void OnReceiveError(CHIP_ERROR error, const Transport::PeerAddress & source, SecureSessionMgrBase * mgr) override
void OnReceiveError(CHIP_ERROR error, const Transport::PeerAddress & source, SecureSessionMgr * mgr) override
{
ESP_LOGE(TAG, "ERROR: %s\n Got UDP error", ErrorStr(error));
statusLED1.BlinkOnError();
}

void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgrBase * mgr) override
void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgr * mgr) override
{
ESP_LOGI(TAG, "Received a new connection.");
}
Expand Down Expand Up @@ -218,15 +219,16 @@ class EchoServerCallback : public SecureSessionMgrDelegate

EchoServerCallback gCallbacks;

SecureSessionMgr<Transport::UDP, // IPV6
Transport::UDP // IPV4
>
sessions;
TransportMgr<Transport::UDP, // IPV6
Transport::UDP // IPV4
>
gTransports;
SecureSessionMgr sessions;

} // namespace

namespace chip {
SecureSessionMgrBase & SessionManager()
SecureSessionMgr & SessionManager()
{
return sessions;
}
Expand All @@ -242,9 +244,11 @@ void PairingComplete(SecurePairingSession * pairing)
void startServer()
{
CHIP_ERROR err = CHIP_NO_ERROR;
err = sessions.Init(kLocalNodeId, &DeviceLayer::SystemLayer,
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6).SetInterfaceId(NULL),
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv4));
err = sessions.Init(kLocalNodeId, &DeviceLayer::SystemLayer);
SuccessOrExit(err);
err = gTransports.Init(&sessions, nullptr,
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6).SetInterfaceId(nullptr),
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv4));
SuccessOrExit(err);

sessions.SetDelegate(&gCallbacks);
Expand Down
2 changes: 1 addition & 1 deletion examples/common/chip-app-server/DataModelHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" {
* @param [in] buffer The buffer holding the message. This function guarantees
* that it will free the buffer before returning.
*/
void HandleDataModelMessage(const PacketHeader & header, System::PacketBuffer * buffer, SecureSessionMgrBase * mgr)
void HandleDataModelMessage(const PacketHeader & header, System::PacketBuffer * buffer, SecureSessionMgr * mgr)
{
EmberApsFrame frame;
bool ok = extractApsFrame(buffer->Start(), buffer->DataLength(), &frame) > 0;
Expand Down
3 changes: 2 additions & 1 deletion examples/common/chip-app-server/RendezvousServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ void RendezvousServer::OnRendezvousConnectionClosed()
ChipLogProgress(AppServer, "OnRendezvousConnectionClosed");
}

void RendezvousServer::OnRendezvousMessageReceived(PacketBuffer * buffer)
void RendezvousServer::OnRendezvousMessageReceived(const PacketHeader & packetHeader, const PeerAddress & peerAddress,
PacketBuffer * buffer)
{
chip::System::PacketBuffer::Free(buffer);
}
Expand Down
15 changes: 9 additions & 6 deletions examples/common/chip-app-server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ServerCallback : public SecureSessionMgrDelegate
{
public:
void OnMessageReceived(const PacketHeader & header, const PayloadHeader & payloadHeader, Transport::PeerConnectionState * state,
System::PacketBuffer * buffer, SecureSessionMgrBase * mgr) override
System::PacketBuffer * buffer, SecureSessionMgr * mgr) override
{
const size_t data_len = buffer->DataLength();
char src_addr[PeerAddress::kMaxToStringSize];
Expand All @@ -76,20 +76,21 @@ class ServerCallback : public SecureSessionMgrDelegate
}
}

void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgrBase * mgr) override
void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgr * mgr) override
{
ChipLogProgress(AppServer, "Received a new connection.");
}
};

DemoSessionManager gSessions;
DemoTransportMgr gTransports;
SecureSessionMgr gSessions;
ServerCallback gCallbacks;
SecurePairingUsingTestSecret gTestPairing;
RendezvousServer gRendezvousServer;

} // namespace

SecureSessionMgrBase & chip::SessionManager()
SecureSessionMgr & chip::SessionManager()
{
return gSessions;
}
Expand All @@ -103,8 +104,7 @@ void InitServer()

InitDataModelHandler();

err = gSessions.Init(EXAMPLE_SERVER_NODEID, &DeviceLayer::SystemLayer,
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6));
err = gSessions.Init(EXAMPLE_SERVER_NODEID, &DeviceLayer::SystemLayer);
SuccessOrExit(err);

// This flag is used to bypass BLE in the cirque test
Expand All @@ -127,6 +127,9 @@ void InitServer()

gSessions.SetDelegate(&gCallbacks);

gTransports.Init(&gSessions, gRendezvousServer.GetRendezvousSession(),
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6));

exit:
if (err != CHIP_NO_ERROR)
{
Expand Down
3 changes: 1 addition & 2 deletions examples/common/chip-app-server/include/DataModelHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ extern "C" {
* @param [in] buffer The buffer holding the message. This function guarantees
* that it will free the buffer before returning.
*/
void HandleDataModelMessage(const chip::PacketHeader & header, chip::System::PacketBuffer * buffer,
chip::SecureSessionMgrBase * mgr);
void HandleDataModelMessage(const chip::PacketHeader & header, chip::System::PacketBuffer * buffer, chip::SecureSessionMgr * mgr);
void InitDataModelHandler();
}
4 changes: 3 additions & 1 deletion examples/common/chip-app-server/include/RendezvousServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ class RendezvousServer : public RendezvousSessionDelegate
void OnRendezvousConnectionOpened() override;
void OnRendezvousConnectionClosed() override;
void OnRendezvousError(CHIP_ERROR err) override;
void OnRendezvousMessageReceived(System::PacketBuffer * buffer) override;
void OnRendezvousMessageReceived(const PacketHeader & packetHeader, const Transport::PeerAddress & peerAddress,
System::PacketBuffer * buffer) override;
void OnRendezvousStatusUpdate(Status status, CHIP_ERROR err) override;
RendezvousSession * GetRendezvousSession() { return &mRendezvousSession; };

private:
RendezvousSession mRendezvousSession;
Expand Down
4 changes: 2 additions & 2 deletions examples/common/chip-app-server/include/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

#pragma once

#include <transport/SecureSessionMgr.h>
#include <transport/TransportMgr.h>
#include <transport/raw/UDP.h>

using DemoSessionManager = chip::SecureSessionMgr<chip::Transport::UDP>;
using DemoTransportMgr = chip::TransportMgr<chip::Transport::UDP>;

/**
* Initialize DataModelHandler and start CHIP datamodel server, the server
Expand Down
2 changes: 1 addition & 1 deletion examples/common/chip-app-server/include/SessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
#include <transport/SecureSessionMgr.h>

namespace chip {
SecureSessionMgrBase & SessionManager();
SecureSessionMgr & SessionManager();
} // namespace chip
27 changes: 15 additions & 12 deletions examples/temperature-measurement-app/esp32/main/ResponseServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <support/ErrorStr.h>
#include <system/SystemPacketBuffer.h>
#include <transport/SecureSessionMgr.h>
#include <transport/TransportMgr.h>
#include <transport/raw/Tuple.h>
#include <transport/raw/UDP.h>

Expand All @@ -61,7 +62,7 @@ class ResponseServerCallback : public SecureSessionMgrDelegate
{
public:
void OnMessageReceived(const PacketHeader & header, const PayloadHeader & payloadHeader, Transport::PeerConnectionState * state,
System::PacketBuffer * buffer, SecureSessionMgrBase * mgr) override
System::PacketBuffer * buffer, SecureSessionMgr * mgr) override
{
CHIP_ERROR err;
const size_t data_len = buffer->DataLength();
Expand Down Expand Up @@ -90,12 +91,12 @@ class ResponseServerCallback : public SecureSessionMgrDelegate
}
}

void OnReceiveError(CHIP_ERROR error, const Transport::PeerAddress & source, SecureSessionMgrBase * mgr) override
void OnReceiveError(CHIP_ERROR error, const Transport::PeerAddress & source, SecureSessionMgr * mgr) override
{
ESP_LOGE(TAG, "ERROR: %s\n Got UDP error", ErrorStr(error));
}

void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgrBase * mgr) override
void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgr * mgr) override
{
ESP_LOGI(TAG, "Received a new connection.");
}
Expand Down Expand Up @@ -127,16 +128,16 @@ class ResponseServerCallback : public SecureSessionMgrDelegate
};

ResponseServerCallback gCallbacks;

SecureSessionMgr<Transport::UDP, // IPV6
Transport::UDP // IPV4
>
sessions;
TransportMgr<Transport::UDP, // IPV6
Transport::UDP // IPV4
>
gTransports;
SecureSessionMgr sessions;

} // namespace

namespace chip {
SecureSessionMgrBase & SessionManager()
SecureSessionMgr & SessionManager()
{
return sessions;
}
Expand All @@ -152,9 +153,11 @@ void PairingComplete(SecurePairingSession * pairing)
void startServer()
{
CHIP_ERROR err = CHIP_NO_ERROR;
err = sessions.Init(kLocalNodeId, &DeviceLayer::SystemLayer,
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6).SetInterfaceId(nullptr),
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv4));
err = sessions.Init(kLocalNodeId, &DeviceLayer::SystemLayer);
SuccessOrExit(err);
err = gTransports.Init(&sessions, nullptr,
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6).SetInterfaceId(nullptr),
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv4));
SuccessOrExit(err);

sessions.SetDelegate(&gCallbacks);
Expand Down
4 changes: 2 additions & 2 deletions src/app/util/chip-message-send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <assert.h>
#include <inet/InetLayer.h> // PacketBuffer and the like
#include <support/logging/CHIPLogging.h>
#include <transport/SecureSessionMgr.h> // For SecureSessionMgrBase
#include <transport/SecureSessionMgr.h> // For SecureSessionMgr

using namespace chip;

Expand All @@ -35,7 +35,7 @@ using namespace chip;
//
// https://github.com/project-chip/connectedhomeip/issues/2566 tracks that API.
namespace chip {
extern SecureSessionMgrBase & SessionManager();
extern SecureSessionMgr & SessionManager();
}

extern "C" {
Expand Down
Loading

0 comments on commit 35d58d5

Please sign in to comment.