Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,42 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <android/api-level.h>
#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <unistd.h>
#define closesocket(_s) close(_s)
#define AZ_EWOULDBLOCK EWOULDBLOCK
#define AZ_EINPROGRESS EINPROGRESS
#define AZ_ECONNREFUSED ECONNREFUSED
#define AZ_EALREADY EALREADY
#define AZ_EISCONN EISCONN
#define AZ_ENETUNREACH ENETUNREACH
#define AZ_ETIMEDOUT ETIMEDOUT
#define SO_NBIO FIONBIO
#define ioctlsocket ioctl
namespace GridMate
{
namespace Platform
{
using SocketType_Platform = int;
}
}
@@ -0,0 +1,14 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <GridMate/Carrier/SocketDriver_Android.h>
@@ -0,0 +1,127 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <GridMate_Traits_Platform.h>
#include <GridMate/Carrier/Utils.h>
#include <GridMate/Carrier/Driver.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <linux/rtnetlink.h>
#include <arpa/inet.h>
#include <unistd.h>
namespace GridMate
{
string Utils::GetMachineAddress(int familyType)
{
string machineName;
struct RTMRequest
{
nlmsghdr m_msghdr;
ifaddrmsg m_msg;
} rtmRequest;
int sock = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
int family = familyType == Driver::BSD_AF_INET ? AF_INET : AF_INET6;
memset(&rtmRequest, 0, sizeof(rtmRequest));
rtmRequest.m_msghdr.nlmsg_len = NLMSG_LENGTH(sizeof(ifaddrmsg));
rtmRequest.m_msghdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT;
rtmRequest.m_msghdr.nlmsg_type = RTM_GETADDR;
rtmRequest.m_msg.ifa_family = family;
rtattr* rtaAttr = reinterpret_cast<rtattr*>(((char*)&rtmRequest) + NLMSG_ALIGN(rtmRequest.m_msghdr.nlmsg_len));
rtaAttr->rta_len = RTA_LENGTH(familyType == Driver::BSD_AF_INET ? 4 : 16);
int res = send(sock, &rtmRequest, rtmRequest.m_msghdr.nlmsg_len, 0);
if (res < 0)
{
close(sock);
AZ_Warning("GridMate", false, "Failed to send rtm request");
return "";
}
const unsigned int k_bufSize = 4096;
char* buf = static_cast<char*>(azmalloc(k_bufSize, 1, GridMateAllocatorMP));
res = recv(sock, buf, k_bufSize, 0);
if (res > 0 && static_cast<unsigned int>(res) < k_bufSize)
{
for (nlmsghdr* nlmp = reinterpret_cast<nlmsghdr*>(buf); static_cast<unsigned int>(res) > sizeof(*nlmp); )
{
int len = nlmp->nlmsg_len;
int reqLen = len - sizeof(*nlmp);
if (reqLen < 0 || len > res || !NLMSG_OK(nlmp, res))
{
AZ_Warning("GridMate", false, "Failed to dispatch rtnetlink request");
break;
}
ifaddrmsg* rtmp = reinterpret_cast<ifaddrmsg*>(NLMSG_DATA(nlmp));
rtattr* rtatp = reinterpret_cast<rtattr*>(IFA_RTA(rtmp));
char address[INET6_ADDRSTRLEN] = { 0 };
bool isLoopback = false;
string devname;
for (int rtattrlen = IFA_PAYLOAD(nlmp); RTA_OK(rtatp, rtattrlen); rtatp = RTA_NEXT(rtatp, rtattrlen))
{
if (rtatp->rta_type == IFA_ADDRESS)
{
in_addr* addr = reinterpret_cast<in_addr*>(RTA_DATA(rtatp));
inet_ntop(family, addr, address, sizeof(address));
static const in6_addr loopbackAddr6[] = { IN6ADDR_LOOPBACK_INIT };
isLoopback |= family == AF_INET && *reinterpret_cast<AZ::u32*>(addr) == 0x0100007F;
isLoopback |= family == AF_INET6 && !memcmp(addr, loopbackAddr6, sizeof(loopbackAddr6));
}
if (rtatp->rta_type == IFA_LABEL)
{
devname = reinterpret_cast<const char*>RTA_DATA(rtatp);
}
}
if (!isLoopback
&& *address
&& (!strcmp(devname.c_str(), "eth0") || !strcmp(devname.c_str(), "wlan0")))
{
machineName = address;
break;
}
res -= NLMSG_ALIGN(len);
nlmp = reinterpret_cast<nlmsghdr*>(((char*)nlmp + NLMSG_ALIGN(len)));
}
}
azfree(buf, GridMateAllocatorMP, k_bufSize);
close(sock);
return machineName;
}
const char* GridMate::Utils::GetBroadcastAddress(int familyType)
{
if (familyType == Driver::BSD_AF_INET6)
{
return "FF02::1";
}
else if (familyType == Driver::BSD_AF_INET)
{
return "255.255.255.255";
}
else
{
return "";
}
}
}
@@ -0,0 +1,28 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <GridMate/String/string.h>
#include <unistd.h>
namespace GridMate
{
namespace Platform
{
void AssignExtendedName(GridMate::string& extendedName)
{
char hostName[64];
gethostname(hostName, AZ_ARRAY_SIZE(hostName));
extendedName = GridMate::string::format("%s", hostName);
}
}
}
@@ -0,0 +1,12 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
@@ -0,0 +1,14 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <GridMate/Session/Session_Android.h>
@@ -0,0 +1,18 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#define AZ_TRAIT_GRIDMATE_ENABLE_OPENSSL 0
#define AZ_TRAIT_GRIDMATE_MAX_PACKET_SEND_SIZE 1400
#define AZ_TRAIT_GRIDMATE_MESSAGE_NO_SIGNAL MSG_NOSIGNAL
#define AZ_TRAIT_GRIDMATE_SECURE_SOCKET_DRIVER_HOOK_ENABLED 0
#define AZ_TRAIT_GRIDMATE_SOCKET_IPV6_SUPPORT_EXTENSION 0
@@ -0,0 +1,14 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <GridMate_Traits_Android.h>
@@ -0,0 +1,16 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# Platform specific cmake file for configuring target compiler/link properties
# based on the active platform
# NOTE: functions in cmake are global, therefore adding functions to this file
# is being avoided to prevent overriding functions declared in other targets platfrom
# specific cmake files
@@ -0,0 +1,22 @@
#
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
# its licensors.
#
# For complete copyright and license terms please see the LICENSE at the root of this
# distribution (the "License"). All use of this software is governed by the License,
# or, if provided, by the license below or the license accompanying this file. Do not
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
set(FILES
../Common/UnixLike/GridMate/Carrier/SocketDriver_UnixLike.cpp
GridMate/Carrier/SocketDriver_Platform.h
GridMate/Carrier/SocketDriver_Android.h
GridMate/Carrier/Utils_Android.cpp
GridMate/Session/LANSession_Android.cpp
GridMate/Session/Session_Platform.h
GridMate/Session/Session_Android.h
GridMate_Traits_Platform.h
GridMate_Traits_Android.h
)