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

03 large weave merge #756

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
712efe2
Add as-is copy of WeaveConnection.
andreilitvin May 5, 2020
f135fb7
Ran automated weave->chip conversion script.
andreilitvin May 5, 2020
c026d2f
Starting to make changes for compilation. Added HostPortList as a dep…
andreilitvin May 5, 2020
0b49339
Updated changes for compilation:
andreilitvin May 5, 2020
8e827e8
Copied over GetPeeerDescription from the messaging layer
andreilitvin May 6, 2020
2328f2a
Added more constants for compilation. At this point only MessageLayer…
andreilitvin May 6, 2020
a0b5ed6
Also added ChipMessageFlags. Apparently this is different from the he…
andreilitvin May 6, 2020
0cd2a55
Compilation now succeeds - added all wrappers for the Message layer i…
andreilitvin May 6, 2020
14b549b
Update to style autoformat
andreilitvin May 12, 2020
03d0f63
Restyled HostPortList. Automated run task did not seem to do this
andreilitvin May 12, 2020
0004b05
Add IdConstants.h to core layer header files list.
andreilitvin May 12, 2020
0e78c59
Addressed code review comments
andreilitvin May 12, 2020
bb99154
Remove reference to a CHIP Service Directory from hostportlist
andreilitvin May 12, 2020
9b720d9
Removed HostPortList usage from chipconnection
andreilitvin May 13, 2020
c9443fe
Remove CHIP_CONFIG_ENABLE_TUNNELING ifdefs
andreilitvin May 13, 2020
f3d2f8a
Removed tunneled data header flags
andreilitvin May 13, 2020
97d10bd
Remove CONFIG_ENABLE_DNS_RESOLVER references
andreilitvin May 13, 2020
dd2e5d2
Remove references to IsIPv6ULA and assume we always send node ids ove…
andreilitvin May 13, 2020
11dc03d
Rename CHIPConnection to CHIPUdpExchange.h.
andreilitvin May 14, 2020
c72611b
Merge branch 'master' into 01_rename_controller_bit
andreilitvin May 15, 2020
8992481
Merge branch '01_rename_controller_bit' into 01_add_connection_class
andreilitvin May 15, 2020
e0df528
Initial CHIPFabricState import.
andreilitvin May 8, 2020
e39267a
Removed a lot of code, keeping only bare minimum function. Removed al…
andreilitvin May 8, 2020
aa76aee
Added random bytes support in the crypto library, added usage in the …
andreilitvin May 8, 2020
472e53a
Fix end container in getting fabric state
andreilitvin May 8, 2020
83c9eaa
Add the ChipFabricState test from weave.
andreilitvin May 11, 2020
024a559
Added copyright updates to header and cpp files
andreilitvin May 11, 2020
7d75ddb
Fabric state test compiles, added test for get and join fabric state
andreilitvin May 11, 2020
8dbf73b
Updated test to verify that clearing fabric state works as expected
andreilitvin May 11, 2020
104097b
Make things compile after merge on top of latest changes
andreilitvin May 15, 2020
77f555c
Added a copy of WeaveBinding into CHIPBinding.
andreilitvin May 15, 2020
4cd2ada
Added a copy of WeaveExchangeMgr into CHIPExchangeMgr.
andreilitvin May 15, 2020
a1bb43f
Added ExchangeContext from Weave.
andreilitvin May 15, 2020
551a291
Initial pass on the binding: remove core include, add wrmp config
andreilitvin May 15, 2020
d8f90fe
Remove encryption/auth from binding. Interlinkage prevents compilatio…
andreilitvin May 15, 2020
f3751cd
Start adding link to exchangemgr header. Does not yet compile
andreilitvin May 15, 2020
2182338
Added the message layer header and source. Stripped out the connectio…
andreilitvin May 15, 2020
ed82ad6
CHIPBinding compiles.
andreilitvin May 15, 2020
ecfb2fa
CHIPMessageLayer compiles now
andreilitvin May 15, 2020
18b667d
ExchangeContext.cpp compiles
andreilitvin May 15, 2020
4d10ea0
CHIPExchangeMgr.cpp now compiles
andreilitvin May 15, 2020
1989f24
Applied code-pretty update
andreilitvin May 15, 2020
e131112
Started to add a demo application for the message layer
andreilitvin May 15, 2020
8ae3d4f
Ensure the message layer app compiles (needed more include updates)
andreilitvin May 15, 2020
092ee6a
Added argument parsing to the main cpp file
andreilitvin May 15, 2020
ca82a5d
Argument parsing now works - forgot help options before
andreilitvin May 15, 2020
b321005
Make things start compiling with message layer includes. Does not lin…
andreilitvin May 15, 2020
7e7a7e0
Link with crypto as well
andreilitvin May 15, 2020
374c650
Code compiles, initializes and even has a 'Listening on' bit
andreilitvin May 15, 2020
020510a
Added shutdown code
andreilitvin May 15, 2020
0c99d26
Support an infinite wait plus control c detection
andreilitvin May 15, 2020
631cbb4
Split out into client and server - make the program act as such
andreilitvin May 15, 2020
8a57ad1
Some work regarding communication. Note that binding still does not work
andreilitvin May 15, 2020
588dd33
Chip binding cannot support dns (host names) right now
andreilitvin May 15, 2020
37ce899
Add ability to send a message over an exchange context
andreilitvin May 19, 2020
19b5b39
More changes for session state in message sending
andreilitvin May 19, 2020
60cf34a
Endpoint refresh, so that UDP messages are attempted to be sent
andreilitvin May 19, 2020
0fbda33
Updates to handle TCP events
andreilitvin May 19, 2020
6c5d235
Needs udp listen to send data over UDP. Although amazingly enough the…
andreilitvin May 19, 2020
3c3d673
Updated message placement
andreilitvin May 19, 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
70 changes: 70 additions & 0 deletions examples/message-layer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#
#
# Copyright (c) 2020 Project CHIP Authors
# Copyright (c) 2019 Google LLC.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# @file
# Makefile for building the CHIP Standalone Example Application.
#

PROJECT_ROOT := $(realpath .)

CHIP_ROOT = $(realpath $(PROJECT_ROOT)/third_party/connectedhomeip)
BUILD_SUPPORT_DIR = $(CHIP_ROOT)/config/standalone

include $(BUILD_SUPPORT_DIR)/standalone-app.mk
include $(BUILD_SUPPORT_DIR)/standalone-chip.mk

APP = chip-message-layer-demo

STD_LIBS += \
-lChipCrypto \
$(OPENSSL_LDFLAGS) $(OPENSSL_LIBS) \
$(CRYPTO_LDFLAGS) $(CRYPTO_LIBS) \
$(MBEDTLS_LDFLAGS) $(MBEDTLS_LIBS)

# TODO: find out why above is not sufficient
STD_LIBS += -lcrypto

SRCS = \
$(PROJECT_ROOT)/main.cpp \
$(NULL)

INC_DIRS = \
$(PROJECT_ROOT) \
$(PROJECT_ROOT)/include \
$(CHIP_ROOT)/src/lib \
$(CHIP_ROOT)/src/ \
$(CHIP_ROOT)/src/system \
$(CHIP_ROOT)/src/controller \
$(CHIP_ROOT)/config/standalone \
$(NULL)

DEFINES = \
USE_APP_CONFIG \
$(NULL)

ifdef BUILD_RELEASE
DEFINES += BUILD_RELEASE=1
else
DEFINES += BUILD_RELEASE=0
endif

CHIP_PROJECT_CONFIG = $(PROJECT_ROOT)/include/CHIPProjectConfig.h

$(call GenerateBuildRules)
281 changes: 281 additions & 0 deletions examples/message-layer/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
#include <iostream>
#include <thread>
#include <chrono>
#include <string>

#include <signal.h>

#include <CHIPVersion.h>

#include <core/CHIPBinding.h>
#include <core/CHIPExchangeMgr.h>
#include <core/CHIPMessageLayer.h>
#include <inet/InetLayer.h>
#include <support/CHIPArgParser.hpp>
#include <support/CodeUtils.h>
#include <system/SystemLayer.h>
#include <controller/CHIPDeviceController.h>

namespace {

using namespace chip;
using namespace chip::ArgParser;

constexpr uint32_t kProfileId = 100;
constexpr uint8_t kMessageType = 123;

#define kToolName "message-layer-demo"

constexpr uint16_t kToolOptListen = 'l';
constexpr uint16_t kToolOptUDPIP = 'u';
constexpr uint16_t kToolOptNodeId = 'n';
constexpr uint16_t kToolOptMessage = 'm';

OptionDef sToolOptionDefs[] = { //
{ "listen", kNoArgument, kToolOptListen },
{ "udp", kNoArgument, kToolOptUDPIP },
{ "node", kArgumentRequired, kToolOptNodeId },
{ "message", kArgumentRequired, kToolOptMessage },
{}
};

constexpr const char * sToolOptionHelp = //
" -l, --listen\n Act as a server (i.e., listen) for packets rather than send them.\n\n"
" -u, --udp\n Use UDP over IP.\n\n"
" -n, --node <Id>\n Use UDP over IP.\n\n"
" -m, --message <Id>\n Message to send over the wire.\n\n";

bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue);
bool HandleNonOptionArgs(const char * aProgram, int argc, char * argv[]);

struct
{
bool Listen = false;
bool Udp = false;
int64_t NodeId = 1;
std::string Message = "This is a message";
} ProgramArguments;

OptionSet sToolOptions = { //
HandleOption, //
sToolOptionDefs, //
"GENERAL OPTIONS", //
sToolOptionHelp
};

HelpOptions sHelpOptions( //
kToolName, //
"Usage: " kToolName " [ <options> ] [ -g <group> [ ... ] -I <interface> ]\n", //
CHIP_VERSION_STRING "\nCopyright (c) 2020 Project CHIP Authors\nAll rights reserved.\n");

static OptionSet * sToolOptionSets[] = { &sToolOptions, &sHelpOptions, NULL };

bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue)
{
switch (aIdentifier)
{
case kToolOptListen:
ProgramArguments.Listen = true;
break;
case kToolOptUDPIP:
ProgramArguments.Udp = true;
break;
case kToolOptNodeId:
ProgramArguments.NodeId = atoll(aValue);
break;
case kToolOptMessage:
ProgramArguments.Message = aValue;
break;
default:
return false;
}
return true;
}

bool HandleNonOptionArgs(const char * aProgram, int argc, char * argv[])
{
if (argc > 0)
{
PrintArgError("%s: unexpected argument: %s\n", aProgram, argv[0]);
return false;
}

return true;
}

volatile bool programStopped = false;
void StopHandler(int s)
{
programStopped = true;
}

void RegisterStopHandler()
{
signal(SIGHUP, StopHandler);
signal(SIGQUIT, StopHandler);
signal(SIGSTOP, StopHandler);
signal(SIGINT, StopHandler);
}
void HandleBindingEvent(void * appState, chip::Binding::EventType event, const chip::Binding::InEventParam & in,
chip::Binding::OutEventParam & out)
{

if (event != chip::Binding::EventType::kEvent_BindingReady)
{
return;
}
std::cout << "Binding ready. Can sent message." << std::endl;

CHIP_ERROR err;
chip::ExchangeContext * exchangeContext = NULL;

err = in.Source->NewExchangeContext(exchangeContext);
SuccessOrExit(err);

{
PacketBuffer * packet = PacketBuffer::NewWithAvailableSize(ProgramArguments.Message.size());
VerifyOrExit(packet != NULL, err = CHIP_ERROR_NO_MEMORY);

packet->SetDataLength(ProgramArguments.Message.size());
memcpy(packet->Start(), ProgramArguments.Message.data(), ProgramArguments.Message.size());
err = exchangeContext->SendMessage(kProfileId, kMessageType, packet);
}

exit:
if (err != CHIP_NO_ERROR)
{
std::cout << "Sent message error: " << ErrorStr(err) << std::endl;
}
else
{
std::cout << "Message has been sent." << std::endl;
}
}

void ConnectToServer(ChipExchangeManager * exchangeMgr)
{
CHIP_ERROR err = CHIP_NO_ERROR;

Binding * binding = exchangeMgr->NewBinding();
VerifyOrExit(binding != NULL, err = CHIP_ERROR_NO_MEMORY);

binding->SetEventCallback(HandleBindingEvent);

{

Binding::Configuration configuration = binding->BeginConfiguration();

if (ProgramArguments.Udp)
{
configuration.Transport_UDP();
}
else
{
configuration.Transport_TCP();
}

Inet::IPAddress address;
VerifyOrExit(Inet::IPAddress::FromString("::1", address), err = CHIP_ERROR_INVALID_ARGUMENT);

err = configuration //
.Target_NodeId(ProgramArguments.NodeId) //
.TargetAddress_IP(address, CHIP_PORT) //
.PrepareBinding();
SuccessOrExit(err);
}

exit:
if (err != CHIP_NO_ERROR)
{
std::cout << "Sent message error: " << ErrorStr(err) << std::endl;
}
}

void ReceiveMessageHandler(ExchangeContext * ec, const IPPacketInfo * pktInfo, const ChipMessageInfo * msgInfo, uint32_t profileId,
uint8_t msgType, PacketBuffer * payload)
{
std::cout << "Received a message type " << static_cast<int>(msgType) << std::endl;

std::string data(reinterpret_cast<const char *>(payload->Start()), payload->DataLength());

std::cout << "Payload of size " << payload->DataLength() << ": '" << data << "'" << std::endl;
}

} // namespace

int main(int argc, char * argv[])
{

if (!ParseArgs(kToolName, argc, argv, sToolOptionSets, HandleNonOptionArgs))
{
std::cout << "Failed to parse arguments" << std::endl;
return 1;
}

CHIP_ERROR err = CHIP_NO_ERROR;

ChipExchangeManager exchangeMgr;
ChipMessageLayer messageLayer;
ChipFabricState fabricState;
chip::DeviceController::ChipDeviceController controller;

ChipMessageLayer::InitContext initContext;

err = fabricState.Init();
SuccessOrExit(err);

err = controller.Init();
SuccessOrExit(err);

initContext.systemLayer = controller.SystemLayer();
initContext.inet = controller.InetLayer();
initContext.fabricState = &fabricState;
initContext.listenTCP = ProgramArguments.Listen;
initContext.listenUDP = ProgramArguments.Listen || ProgramArguments.Udp;

err = messageLayer.Init(&initContext);
SuccessOrExit(err);

err = exchangeMgr.Init(&messageLayer);
SuccessOrExit(err);

err = exchangeMgr.RegisterUnsolicitedMessageHandler(kProfileId, ReceiveMessageHandler, nullptr);
SuccessOrExit(err);

if (ProgramArguments.Listen)
{
std::cout << "Acting as a SERVER ..." << std::endl;
std::cout << "Node ID: " << fabricState.LocalNodeId << std::endl;
}
else
{
std::cout << "Acting as a CLIENT ..." << std::endl;
ConnectToServer(&exchangeMgr);
}

err = messageLayer.RefreshEndpoints();
SuccessOrExit(err);

RegisterStopHandler();
while (!programStopped)
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
controller.ServiceEvents();
}

// TODO(Andrei): RAII would be nice here
exchangeMgr.Shutdown();
controller.Shutdown();

exit:
if (err != CHIP_NO_ERROR)
{
std::cout << "FAILED: " << ErrorStr(err) << std::endl;
}
else
{
std::cout << "DONE!" << std::endl;
}

return 0;
}
1 change: 1 addition & 0 deletions examples/message-layer/third_party/connectedhomeip
Loading