Merge pull request #9 from presslab-us/development

merge presslab-us changes
pull/11/head
Matthew Hilton 2020-10-11 00:32:07 +01:00 committed by GitHub
commit ac688560ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 164 additions and 13 deletions

View File

@ -0,0 +1,27 @@
/*
* This file is part of aasdk library project.
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
*
* aasdk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* aasdk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with aasdk. If not, see <http://www.gnu.org/licenses/>.
*/
syntax="proto2";
package f1x.aasdk.proto.messages;
message WifiInfoRequest
{
required string ip_address = 1;
optional uint32 port = 2;
}

View File

@ -0,0 +1,42 @@
/*
* This file is part of aasdk library project.
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
*
* aasdk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* aasdk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with aasdk. If not, see <http://www.gnu.org/licenses/>.
*/
syntax = "proto2";
package f1x.aasdk.proto.messages;
message WifiInfoResponse {
optional string ip_address = 1;
optional uint32 port = 2;
required Status status = 3;
enum Status {
STATUS_UNSOLICITED_MESSAGE = 1;
STATUS_SUCCESS = 0;
STATUS_NO_COMPATIBLE_VERSION = -1;
STATUS_WIFI_INACCESSIBLE_CHANNEL = -2;
STATUS_WIFI_INCORRECT_CREDENTIALS = -3;
STATUS_PROJECTION_ALREADY_STARTED = -4;
STATUS_WIFI_DISABLED = -5;
STATUS_WIFI_NOT_YET_STARTED = -6;
STATUS_INVALID_HOST = -7;
STATUS_NO_SUPPORTED_WIFI_CHANNELS = -8;
STATUS_INSTRUCT_USER_TO_CHECK_THE_PHONE = -9;
STATUS_PHONE_WIFI_DISABLED = -10;
}
}

View File

@ -0,0 +1,47 @@
/*
* This file is part of aasdk library project.
* Copyright (C) 2018 f1x.studio (Michal Szwaj)
*
* aasdk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
* aasdk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with aasdk. If not, see <http://www.gnu.org/licenses/>.
*/
syntax = "proto2";
package f1x.aasdk.proto.messages;
message WifiSecurityReponse {
required string ssid = 1; //mo15384a
required string key = 2; //mo15385b
required string bssid = 3; //mo15386c
required SecurityMode security_mode = 4;
required AccessPointType access_point_type = 5;
enum SecurityMode {
UNKNOWN_SECURITY_MODE = 0;
OPEN = 1;
WEP_64 = 2;
WEP_128 = 3;
WPA_PERSONAL = 4;
WPA2_PERSONAL = 8;
WPA_WPA2_PERSONAL = 12;
WPA_ENTERPRISE = 20;
WPA2_ENTERPRISE = 24;
WPA_WPA2_ENTERPRISE = 28;
}
enum AccessPointType {
STATIC = 0;
DYNAMIC = 1;
}
}

View File

@ -23,7 +23,7 @@
#include <f1x/aasdk/Messenger/ICryptor.hpp>
#include <f1x/aasdk/Messenger/FrameHeader.hpp>
#include <f1x/aasdk/Messenger/FrameSize.hpp>
#include <f1x/aasdk/Messenger/FrameType.hpp>
namespace f1x
{
namespace aasdk
@ -51,6 +51,8 @@ private:
FrameType recentFrameType_;
ReceivePromise::Pointer promise_;
Message::Pointer message_;
std::map<messenger::ChannelId, Message::Pointer> channel_assembly_buffers;
};
}

View File

@ -49,6 +49,7 @@ private:
void outStreamMessageHandler(ChannelSendQueue::iterator queueElement);
void rejectReceivePromiseQueue(const error::Error& e);
void rejectSendPromiseQueue(const error::Error& e);
void parseMessage(Message::Pointer message, ReceivePromise::Pointer promise);
boost::asio::io_service::strand receiveStrand_;
boost::asio::io_service::strand sendStrand_;

View File

@ -128,7 +128,9 @@ common::Data createData(const DataConstBuffer& buffer)
std::string dump(const Data& data)
{
return dump(DataConstBuffer(data));
std::string buffer;
boost::algorithm::hex(data, back_inserter(buffer));
return buffer;
}
std::string dump(const DataConstBuffer& buffer)

View File

@ -17,6 +17,7 @@
*/
#include <f1x/aasdk/Messenger/Message.hpp>
#include <f1x/aasdk/Common/Log.hpp>
namespace f1x
{
@ -83,6 +84,9 @@ void Message::insertPayload(const common::Data& payload)
void Message::insertPayload(const google::protobuf::Message& message)
{
if (message.GetTypeName() != "f1x.aasdk.proto.messages.AVMediaAckIndication") {
AASDK_LOG(debug) << message.GetTypeName() << " - " + message.DebugString();
}
auto offset = payload_.size();
payload_.resize(payload_.size() + message.ByteSize());

View File

@ -18,7 +18,9 @@
#include <f1x/aasdk/Messenger/MessageInStream.hpp>
#include <f1x/aasdk/Error/Error.hpp>
#include <f1x/aasdk/Common/Log.hpp>
#include <iostream>
namespace f1x
{
namespace aasdk
@ -63,19 +65,32 @@ void MessageInStream::startReceive(ReceivePromise::Pointer promise)
void MessageInStream::receiveFrameHeaderHandler(const common::DataConstBuffer& buffer)
{
FrameHeader frameHeader(buffer);
if (buffer.cdata[0] != 3) {
AASDK_LOG(debug) << "Message from channel " << std::to_string(buffer.cdata[0]);
}
if(message_ == nullptr)
if(message_ != nullptr && message_->getChannelId() != frameHeader.getChannelId())
{
// we have interleaved channels, stop working on the old one and store it for later; Switch to the new one
channel_assembly_buffers[message_->getChannelId()] = message_;
message_ = nullptr;
// message_.reset();
// promise_->reject(error::Error(error::ErrorCode::MESSENGER_INTERTWINED_CHANNELS));
// promise_.reset();
// return;
}
auto prevBuffer = channel_assembly_buffers.find(frameHeader.getChannelId());
if(prevBuffer != channel_assembly_buffers.end()){ // is there previous data in our map?
if(frameHeader.getType()!=FrameType::FIRST) //only use the data if we're not on a new frame, otherwise disregard
message_ = prevBuffer->second;
else{
message_ = std::make_shared<Message>(frameHeader.getChannelId(), frameHeader.getEncryptionType(), frameHeader.getMessageType());
}
channel_assembly_buffers.erase(prevBuffer); // get rid of the previously stored data because it's now our working data.
}
else if(message_ == nullptr){
message_ = std::make_shared<Message>(frameHeader.getChannelId(), frameHeader.getEncryptionType(), frameHeader.getMessageType());
}
else if(message_->getChannelId() != frameHeader.getChannelId())
{
message_.reset();
promise_->reject(error::Error(error::ErrorCode::MESSENGER_INTERTWINED_CHANNELS));
promise_.reset();
return;
}
recentFrameType_ = frameHeader.getType();
const size_t frameSize = FrameSize::getSizeOf(frameHeader.getType() == FrameType::FIRST ? FrameSizeType::EXTENDED : FrameSizeType::SHORT);

View File

@ -19,6 +19,7 @@
#include <boost/endian/conversion.hpp>
#include <f1x/aasdk/Error/Error.hpp>
#include <f1x/aasdk/Messenger/Messenger.hpp>
#include <f1x/aasdk/Common/Log.hpp>
namespace f1x
{
@ -41,7 +42,7 @@ void Messenger::enqueueReceive(ChannelId channelId, ReceivePromise::Pointer prom
receiveStrand_.dispatch([this, self = this->shared_from_this(), channelId, promise = std::move(promise)]() mutable {
if(!channelReceiveMessageQueue_.empty(channelId))
{
promise->resolve(std::move(channelReceiveMessageQueue_.pop(channelId)));
this->parseMessage(channelReceiveMessageQueue_.pop(channelId), promise);
}
else
{
@ -73,10 +74,13 @@ void Messenger::enqueueSend(Message::Pointer message, SendPromise::Pointer promi
void Messenger::inStreamMessageHandler(Message::Pointer message)
{
auto channelId = message->getChannelId();
if (message->getChannelId() != ChannelId::VIDEO) {
//AASDK_LOG(debug) << channelIdToString(message->getChannelId()) << ": " << common::dump(message->getPayload());
}
if(channelReceivePromiseQueue_.isPending(channelId))
{
channelReceivePromiseQueue_.pop(channelId)->resolve(std::move(message));
this->parseMessage(message, channelReceivePromiseQueue_.pop(channelId));
}
else
{
@ -92,6 +96,13 @@ void Messenger::inStreamMessageHandler(Message::Pointer message)
}
}
void Messenger::parseMessage(Message::Pointer message, ReceivePromise::Pointer promise) {
if (message->getChannelId() != ChannelId::VIDEO) {
//AASDK_LOG(debug) << channelIdToString(message->getChannelId()) << " " << MessageId(message->getPayload());
}
promise->resolve(message);
}
void Messenger::doSend()
{
auto queueElementIter = channelSendPromiseQueue_.begin();