Skip to content

Commit

Permalink
Update SecureSessionManager init due to API changes in Transport
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca authored and restyled-io[bot] committed Dec 2, 2020
1 parent 7b88fcf commit ccef55c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
21 changes: 9 additions & 12 deletions src/messaging/tests/echo/echo_requester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ constexpr int32_t gEchoInterval = 1000000;
// The EchoClient object.
Protocols::EchoClient gEchoClient;

SecureSessionMgr<Transport::UDP> gSessionManager;
TransportMgr<Transport::UDP> gTransportManager;

SecureSessionMgr gSessionManager;

Inet::IPAddress gDestAddr;

Expand Down Expand Up @@ -189,21 +191,19 @@ int main(int argc, char * argv[])
ExitNow(err = CHIP_ERROR_INVALID_ARGUMENT);
}

// Initialize the CHIP stack as the client.
InitializeChip();

// Initialize Secure Session Manager.
err = gSessionManager.Init(kClientDeviceId, &DeviceLayer::SystemLayer,
Transport::UdpListenParameters(&DeviceLayer::InetLayer)
.SetAddressType(Inet::kIPAddressType_IPv4)
.SetListenPort(ECHO_CLIENT_PORT));
err = gTransportManager.Init(Transport::UdpListenParameters(&DeviceLayer::InetLayer)
.SetAddressType(Inet::kIPAddressType_IPv4)
.SetListenPort(ECHO_CLIENT_PORT));
SuccessOrExit(err);

err = gSessionManager.Init(kClientDeviceId, &DeviceLayer::SystemLayer, &gTransportManager);
SuccessOrExit(err);

// Initialize Exchange Manager.
err = gExchangeManager.Init(&gSessionManager);
SuccessOrExit(err);

// Initialize the EchoClient application.
err = gEchoClient.Init(&gExchangeManager);
SuccessOrExit(err);

Expand All @@ -217,7 +217,6 @@ int main(int argc, char * argv[])
// Connection has been established. Now send the EchoRequests.
for (unsigned int i = 0; i < kMaxEchoCount; i++)
{
// Send an EchoRequest message.
if (SendEchoRequest() != CHIP_NO_ERROR)
{
printf("Send request failed: %s\n", ErrorStr(err));
Expand All @@ -238,10 +237,8 @@ int main(int argc, char * argv[])
}
}

// Shutdown the EchoClient.
gEchoClient.Shutdown();

// Shutdown the CHIP stack.
ShutdownChip();

exit:
Expand Down
25 changes: 13 additions & 12 deletions src/messaging/tests/echo/echo_responder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,38 @@
#include <protocols/echo/Echo.h>
#include <support/ErrorStr.h>

namespace {

// The EchoServer object.
static Protocols::EchoServer gEchoServer;
static SecureSessionMgr<Transport::UDP> gSessionManager;
static SecurePairingUsingTestSecret gTestPairing;
Protocols::EchoServer gEchoServer;
TransportMgr<Transport::UDP> gTransportManager;
SecureSessionMgr gSessionManager;
SecurePairingUsingTestSecret gTestPairing;

// Callback handler when a CHIP EchoRequest is received.
static void HandleEchoRequestReceived(NodeId nodeId, System::PacketBuffer * payload)
void HandleEchoRequestReceived(NodeId nodeId, System::PacketBuffer * payload)
{
printf("Echo Request from node %lu, len=%u ... sending response.\n", nodeId, payload->DataLength());
}

} // namespace

int main(int argc, char * argv[])
{
CHIP_ERROR err = CHIP_NO_ERROR;
Optional<Transport::PeerAddress> peer(Transport::Type::kUndefined);

// Initialize the CHIP stack as the server.
InitializeChip();

// Initialize Secure Session Manager.
err = gSessionManager.Init(kServerDeviceId, &DeviceLayer::SystemLayer,
Transport::UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(Inet::kIPAddressType_IPv4));
err = gTransportManager.Init(Transport::UdpListenParameters(&DeviceLayer::InetLayer).SetAddressType(Inet::kIPAddressType_IPv4));
SuccessOrExit(err);

err = gSessionManager.Init(kServerDeviceId, &DeviceLayer::SystemLayer, &gTransportManager);
SuccessOrExit(err);

// Initialize Exchange Manager.
err = gExchangeManager.Init(&gSessionManager);
SuccessOrExit(err);

// Initialize the EchoServer application.
err = gEchoServer.Init(&gExchangeManager);
SuccessOrExit(err);

Expand All @@ -81,10 +84,8 @@ int main(int argc, char * argv[])
exit(EXIT_FAILURE);
}

// Shutdown the CHIP EchoServer.
gEchoServer.Shutdown();

// Shutdown the CHIP stack.
ShutdownChip();

return EXIT_SUCCESS;
Expand Down

0 comments on commit ccef55c

Please sign in to comment.