+++ /dev/null
-#include "crypto.h"
-
-using STG::SGCP::CryptoProto;
-
-CryptoProto::CryptoProto(const std::string& key, TransportProto* underlying)
- : m_underlying(underlying)
-{
-}
-
-CryptoProto::~CryptoProto()
-{
- delete m_underlying;
-}
-
-void CryptoProto::connect(const std::string& address, uint16_t port)
-{
- m_underlying->connect(address, port);
-}
-
-ssize_t CryptoProto::write(const void* buf, size_t size)
-{
- // TODO: to implement
- return m_underlying->write(buf, size);
-}
-
-ssize_t CryptoProto::read(void* buf, size_t size)
-{
- // TODO: to implement
- return m_underlying->read(buf, size);
-}
+++ /dev/null
-#ifndef __STG_SGCP_CRYPTO_H__
-#define __STG_SGCP_CRYPTO_H__
-
-/*
- * This program 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 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#include "stg/sgcp_transport.h"
-
-#include "stg/os_int.h"
-
-#include <string>
-
-#include <unistd.h> // ssize_t
-
-namespace STG
-{
-namespace SGCP
-{
-
-class CryptoProto : public TransportProto
-{
- public:
- CryptoProto(const std::string& key, TransportProto* underlying);
- virtual ~CryptoProto();
-
- virtual void connect(const std::string& address, uint16_t port);
- virtual ssize_t write(const void* buf, size_t size);
- virtual ssize_t read(void* buf, size_t size);
-
- private:
- TransportProto* m_underlying;
-};
-
-} // namespace SGCP
-} // namespace STG
-
-#endif
+++ /dev/null
-#include "udp.h"
-
-#include "stg/sgcp_utils.h"
-
-#include <cerrno>
-#include <cstring>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/udp.h>
-
-using STG::SGCP::UDPProto;
-
-UDPProto::UDPProto()
- : m_sock(socket(AF_INET, SOCK_DGRAM, 0))
-{
-}
-
-UDPProto::~UDPProto()
-{
- close(m_sock);
-}
-
-void UDPProto::connect(const std::string& address, uint16_t port)
-{
- std::vector<in_addr> addrs = resolve(address);
-
- for (size_t i = 0; i < addrs.size(); ++i) {
- sockaddr_in addr;
- addr.sin_family = AF_INET;
- addr.sin_port = hton(port);
- addr.sin_addr = addrs[i];
-
- if (::connect(m_sock, reinterpret_cast<const sockaddr*>(&addr), sizeof(addr)) == 0)
- return;
-
- close(m_sock);
- m_sock = socket(AF_INET, SOCK_DGRAM, 0);
- }
- throw Error("No more addresses to connect to.");
-}
-
-ssize_t UDPProto::write(const void* buf, size_t size)
-{
- return ::write(m_sock, buf, size);
-}
-
-ssize_t UDPProto::read(void* buf, size_t size)
-{
- return ::read(m_sock, buf, size);
-}
+++ /dev/null
-#ifndef __STG_SGCP_UDP_H__
-#define __STG_SGCP_UDP_H__
-
-/*
- * This program 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 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
-#include "stg/sgcp_transport.h"
-
-#include "stg/os_int.h"
-
-#include <string>
-
-#include <unistd.h> // ssize_t
-
-namespace STG
-{
-namespace SGCP
-{
-
-class UDPProto : public TransportProto
-{
- public:
- UDPProto();
- virtual ~UDPProto();
-
- virtual void connect(const std::string& address, uint16_t port);
- virtual ssize_t write(const void* buf, size_t size);
- virtual ssize_t read(void* buf, size_t size);
-
- private:
- int m_sock;
-};
-
-} // namespace SGCP
-} // namespace STG
-
-#endif
+++ /dev/null
-#include "stg/sgcp_utils.h"
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-
-std::vector<in_addr> STG::SGCP::resolve(const std::string& address)
-{
- addrinfo* result = NULL;
-
- addrinfo hints;
- memset(&hints, 0, sizeof(hints));
-
- hints.ai_family = AF_INET; /* Allow IPv4 */
- hints.ai_socktype = 0; /* Datagram socket */
- hints.ai_flags = 0; /* For wildcard IP address */
- hints.ai_protocol = 0; /* Any protocol */
- hints.ai_canonname = NULL;
- hints.ai_addr = NULL;
- hints.ai_next = NULL;
-
- int res = getaddrinfo(address.c_str(), NULL, &hints, &result);
- if (res != 0)
- throw TransportProto::Error(gai_error(res));
-
- std::vector as;
- for (const addrinfo* p = result; p != NULL; p = p->next)
- as.push_back(p->ai_addr.sin_addr);
- return as;
-}