Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple transport from session management. #1424

Merged
merged 34 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ebdd6a4
Make callbacks take a PeerAddress instead of a packet info.
andreilitvin Jun 30, 2020
ff81ea0
Separate transport from session management.
andreilitvin Jun 30, 2020
0e71327
Add UDP include for nrf example
andreilitvin Jun 30, 2020
ec2c1c8
Add a tuple of transports ... messy template but should compile to cl…
andreilitvin Jun 30, 2020
b84b944
Add support for callback setting
andreilitvin Jun 30, 2020
f42a1d9
Remove rogue debug log
andreilitvin Jun 30, 2020
1819f88
Merge branch 'master' into 02_multi_transport
andreilitvin Jun 30, 2020
8b92442
Merge branch 'master' into 02_multi_transport
andreilitvin Jul 2, 2020
9b94f8a
Update session manager to include transports as members
andreilitvin Jul 2, 2020
a9fa975
Fix ESP compilation
andreilitvin Jul 2, 2020
af28f50
Update nrf typos
andreilitvin Jul 2, 2020
e5af948
Fix return in mgr test
andreilitvin Jul 2, 2020
336fa1c
Include server.h to have the typedef for demo session mgr type
andreilitvin Jul 2, 2020
da321b2
Add tuple.h in automake config
andy31415 Jul 2, 2020
7fa6825
Remove some obsolete and unused definitions
andy31415 Jul 2, 2020
18edd49
Remote static from anonymous namespace: it is not needed there
andy31415 Jul 2, 2020
e1fe0cd
Update comment to state SessionMgrBASE instead of SesionMgr
andy31415 Jul 2, 2020
596d331
Merge branch 'master' into 02_multi_transport
andy31415 Jul 3, 2020
b9dbc61
Add include to server cpp file
andy31415 Jul 3, 2020
5df4d49
Fix session mgr data type
andy31415 Jul 3, 2020
12d9844
Compiles nrf finally - checked locally
andy31415 Jul 3, 2020
355d2a0
Fix awkward comment based on code review
andy31415 Jul 7, 2020
6ba54e8
Added a lot of doxygen comments based on code review requests
andy31415 Jul 7, 2020
22988be
Added overload doxygen comment
andy31415 Jul 7, 2020
11d1de1
Updated param to tparam
andy31415 Jul 7, 2020
9245690
Merge branch 'master' into 02_multi_transport
andy31415 Jul 7, 2020
68305c9
Updated two more parameters to tparam
andy31415 Jul 8, 2020
fca634c
Merge branch 'master' into 02_multi_transport
andy31415 Jul 8, 2020
3aebe81
Undo some repo deletion
andy31415 Jul 8, 2020
a92b5a4
Merge branch 'master' into 02_multi_transport
andy31415 Jul 9, 2020
14110e7
Doxygen fixes'
andy31415 Jul 9, 2020
fde1fc8
Ensure Send buffer really calls buffer free even if no underlying tra…
andy31415 Jul 9, 2020
8b02e26
Fix the free of packet buffers
andy31415 Jul 9, 2020
cdc7a89
Update number order for Tuple equivalence example
andy31415 Jul 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/common/QRCode/repo
Submodule repo deleted from 08ac80
1 change: 0 additions & 1 deletion examples/common/m5stack-tft/repo
Submodule repo deleted from 35be97
29 changes: 13 additions & 16 deletions examples/platform/nrf528xx/app/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
#include <support/ErrorStr.h>
#include <system/SystemPacketBuffer.h>
#include <transport/SecureSessionMgr.h>
#include <transport/UDP.h>

#include "Server.h"
#include "chip-zcl/chip-zcl.h"

extern "C" {
Expand Down Expand Up @@ -68,7 +70,7 @@ class ServerCallback : public SecureSessionMgrCallback
{
public:
virtual void OnMessageReceived(const MessageHeader & header, Transport::PeerConnectionState * state,
System::PacketBuffer * buffer, SecureSessionMgr * mgr)
System::PacketBuffer * buffer, SecureSessionMgrBase * mgr)
{
const size_t data_len = buffer->DataLength();
char src_addr[PeerAddress::kMaxToStringSize];
Expand All @@ -94,7 +96,7 @@ class ServerCallback : public SecureSessionMgrCallback
}
}

virtual void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgr * mgr)
virtual void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgrBase * mgr)
{
CHIP_ERROR err;

Expand Down Expand Up @@ -135,15 +137,21 @@ static ServerCallback gCallbacks;

} // namespace

void InitDataModelHandler()
{
chipZclEndpointInit();
}

// The echo server assumes the platform's networking has been setup already
void SetupTransport(IPAddressType type, SecureSessionMgr * transport)
void StartServer(DemoSessionManager * sessions)
{
CHIP_ERROR err = CHIP_NO_ERROR;

err = transport->Init(EXAMPLE_SERVER_NODEID, &DeviceLayer::InetLayer, UdpListenParameters().SetAddressType(type));
err = sessions->Init(EXAMPLE_SERVER_NODEID, &DeviceLayer::SystemLayer,
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6));
SuccessOrExit(err);

transport->SetDelegate(&gCallbacks);
sessions->SetDelegate(&gCallbacks);

exit:
if (err != CHIP_NO_ERROR)
Expand All @@ -155,14 +163,3 @@ void SetupTransport(IPAddressType type, SecureSessionMgr * transport)
NRF_LOG_INFO("Lock Server Listening...");
}
}

// The echo server assumes the platform's networking has been setup already
void StartServer(SecureSessionMgr * transport_ipv6)
{
SetupTransport(kIPAddressType_IPv6, transport_ipv6);
}

void InitDataModelHandler()
{
chipZclEndpointInit();
}
4 changes: 2 additions & 2 deletions examples/platform/nrf528xx/app/chipinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ extern "C" {
using namespace ::chip;
using namespace ::chip::DeviceLayer;

chip::SecureSessionMgr sTransportIPv6;
DemoSessionManager sessions;

static void * ot_calloc(size_t n, size_t size)
{
Expand Down Expand Up @@ -144,7 +144,7 @@ ret_code_t ChipInit()

// Init ZCL Data Model
InitDataModelHandler();
StartServer(&sTransportIPv6);
StartServer(&sessions);

return ret;
}
5 changes: 3 additions & 2 deletions examples/platform/nrf528xx/app/include/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
#include <inet/InetLayer.h>
#include <system/SystemPacketBuffer.h>
#include <transport/SecureSessionMgr.h>
#include <transport/UDP.h>

void SetupTransport(chip::Inet::IPAddressType type, chip::SecureSessionMgr * transport);
void StartServer(chip::SecureSessionMgr * transport_ipv6);
using DemoSessionManager = chip::SecureSessionMgr<chip::Transport::UDP>;

void StartServer(DemoSessionManager * sessions);
void InitDataModelHandler();

#endif // NRF5_COMMON_SERVER_H
39 changes: 18 additions & 21 deletions examples/wifi-echo/server/esp32/main/EchoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <support/ErrorStr.h>
#include <system/SystemPacketBuffer.h>
#include <transport/SecureSessionMgr.h>
#include <transport/Tuple.h>
#include <transport/UDP.h>

#include "DataModelHandler.h"
Expand Down Expand Up @@ -134,7 +135,7 @@ class EchoServerCallback : public SecureSessionMgrCallback
{
public:
void OnMessageReceived(const MessageHeader & header, Transport::PeerConnectionState * state, System::PacketBuffer * buffer,
SecureSessionMgr * mgr) override
SecureSessionMgrBase * mgr) override
{
CHIP_ERROR err;
const size_t data_len = buffer->DataLength();
Expand Down Expand Up @@ -191,13 +192,13 @@ class EchoServerCallback : public SecureSessionMgrCallback
}
}

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

void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgr * mgr) override
void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgrBase * mgr) override
{
CHIP_ERROR err;

Expand Down Expand Up @@ -237,25 +238,28 @@ class EchoServerCallback : public SecureSessionMgrCallback
}
};

static EchoServerCallback gCallbacks;
EchoServerCallback gCallbacks;

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

} // namespace

// The echo server assumes the platform's networking has been setup already
void setupTransport(IPAddressType type, SecureSessionMgr * transport)
void startServer()
{
CHIP_ERROR err = CHIP_NO_ERROR;
struct netif * netif = NULL;

if (type == kIPAddressType_IPv6)
{
tcpip_adapter_get_netif(TCPIP_ADAPTER_IF_AP, (void **) &netif);
}
CHIP_ERROR err = CHIP_NO_ERROR;
struct netif * ipV6NetIf = NULL;
tcpip_adapter_get_netif(TCPIP_ADAPTER_IF_AP, (void **) &ipV6NetIf);

err = transport->Init(kLocalNodeId, &DeviceLayer::InetLayer, UdpListenParameters().SetAddressType(type).SetInterfaceId(netif));
err = sessions.Init(kLocalNodeId, &DeviceLayer::SystemLayer,
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv6).SetInterfaceId(ipV6NetIf),
UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(kIPAddressType_IPv4));
SuccessOrExit(err);

transport->SetDelegate(&gCallbacks);
sessions.SetDelegate(&gCallbacks);

exit:
if (err != CHIP_NO_ERROR)
Expand All @@ -267,10 +271,3 @@ void setupTransport(IPAddressType type, SecureSessionMgr * transport)
ESP_LOGI(TAG, "Echo Server Listening...");
}
}

// The echo server assumes the platform's networking has been setup already
void startServer(SecureSessionMgr * transport_ipv4, SecureSessionMgr * transport_ipv6)
{
setupTransport(kIPAddressType_IPv6, transport_ipv6);
setupTransport(kIPAddressType_IPv4, transport_ipv4);
}
9 changes: 3 additions & 6 deletions examples/wifi-echo/server/esp32/main/wifi-echo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
using namespace ::chip;
using namespace ::chip::DeviceLayer;

extern void startServer(SecureSessionMgr * transportIPv4, SecureSessionMgr * transportIPv6);
extern void startServer();

#if CONFIG_USE_ECHO_CLIENT
extern void startClient(void);
#endif // CONFIG_USE_ECHO_CLIENT
Expand Down Expand Up @@ -106,10 +107,6 @@ static EchoDeviceCallbacks EchoCallbacks;

namespace {

// Globals as these are large and will not fit onto the stack
SecureSessionMgr sTransportIPv4;
SecureSessionMgr sTransportIPv6;

std::vector<Button> buttons = { Button(), Button(), Button() };
std::vector<gpio_num_t> button_gpios = { BUTTON_1_GPIO_NUM, BUTTON_2_GPIO_NUM, BUTTON_3_GPIO_NUM };

Expand Down Expand Up @@ -401,7 +398,7 @@ extern "C" void app_main()

// Start the Echo Server
InitDataModelHandler();
startServer(&sTransportIPv4, &sTransportIPv6);
startServer();
#if CONFIG_USE_ECHO_CLIENT
startClient();
#endif
Expand Down
9 changes: 5 additions & 4 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,10 @@ CHIP_ERROR ChipDeviceController::ConnectDevice(NodeId remoteDeviceId, IPAddress
mAppReqState = appReqState;
mOnNewConnection = onConnected;

mSessionManager = new SecureSessionMgr();
mSessionManager = new SecureSessionMgr<Transport::UDP>();

err = mSessionManager->Init(mLocalDeviceId, mInetLayer, Transport::UdpListenParameters().SetAddressType(deviceAddr.Type()));
err = mSessionManager->Init(mLocalDeviceId, mSystemLayer,
Transport::UdpListenParameters(mInetLayer).SetAddressType(deviceAddr.Type()));
SuccessOrExit(err);

mSessionManager->SetDelegate(this);
Expand Down Expand Up @@ -341,13 +342,13 @@ void ChipDeviceController::ClearRequestState()
}
}

void ChipDeviceController::OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgr * mgr)
void ChipDeviceController::OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgrBase * mgr)
{
mOnNewConnection(this, state, mAppReqState);
}

void ChipDeviceController::OnMessageReceived(const MessageHeader & header, Transport::PeerConnectionState * state,
System::PacketBuffer * msgBuf, SecureSessionMgr * mgr)
System::PacketBuffer * msgBuf, SecureSessionMgrBase * mgr)
{
if (header.GetSourceNodeId().HasValue())
{
Expand Down
11 changes: 5 additions & 6 deletions src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ typedef void (*MessageReceiveHandler)(ChipDeviceController * deviceController, v

class DLL_EXPORT ChipDeviceController : public SecureSessionMgrCallback
{
friend class ChipDeviceControllerCallback;

public:
ChipDeviceController();

Expand Down Expand Up @@ -157,9 +159,9 @@ class DLL_EXPORT ChipDeviceController : public SecureSessionMgrCallback
CHIP_ERROR GetLayers(Layer ** systemLayer, InetLayer ** inetLayer);

virtual void OnMessageReceived(const MessageHeader & header, Transport::PeerConnectionState * state,
System::PacketBuffer * msgBuf, SecureSessionMgr * mgr);
System::PacketBuffer * msgBuf, SecureSessionMgrBase * mgr);

virtual void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgr * mgr);
virtual void OnNewConnection(Transport::PeerConnectionState * state, SecureSessionMgrBase * mgr);

private:
enum
Expand All @@ -178,10 +180,7 @@ class DLL_EXPORT ChipDeviceController : public SecureSessionMgrCallback
System::Layer * mSystemLayer;
Inet::InetLayer * mInetLayer;

// TODO: CHIPDeviceController assumes a single device connection, where as
// session manager handles multiple connections. Need to finalize design on this
// as otherwise a single connection may end up processing data from other peers.
SecureSessionMgr * mSessionManager;
SecureSessionMgr<Transport::UDP> * mSessionManager;

ConnectionState mConState;
void * mAppReqState;
Expand Down
6 changes: 3 additions & 3 deletions src/transport/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ class Base : public ReferenceCounted<Base>
virtual CHIP_ERROR SendMessage(const MessageHeader & header, const PeerAddress & address, System::PacketBuffer * msgBuf) = 0;

/**
* Get the path that this transport is associated with.
* Determine if this transport can SendMessage to the specified peer address.
*
* Within a system, only one transport should be associated with a path.
* Generally it is expected that a transport can send to any peer from which it receives a message.
*/
virtual Type GetType() = 0;
virtual bool CanSendToPeer(const Transport::PeerAddress & address) = 0;

protected:
/**
Expand Down
Loading