Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NFD_FACE_TCP_FACE_HPP |
| 8 | #define NFD_FACE_TCP_FACE_HPP |
| 9 | |
| 10 | #include "stream-face.hpp" |
| 11 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 12 | namespace nfd |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 13 | { |
| 14 | |
| 15 | /** |
| 16 | * \brief Implementation of Face abstraction that uses TCP |
| 17 | * as underlying transport mechanism |
| 18 | */ |
| 19 | class TcpFace : public StreamFace<boost::asio::ip::tcp> |
| 20 | { |
| 21 | public: |
Alexander Afanasyev | d32cb96 | 2014-01-28 12:43:47 -0800 | [diff] [blame] | 22 | typedef boost::asio::ip::tcp protocol; |
| 23 | |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 24 | explicit |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 25 | TcpFace(const shared_ptr<protocol::socket>& socket); |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 26 | }; |
| 27 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 28 | // |
| 29 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 30 | /** |
| 31 | * \brief Implementation of Face abstraction that uses TCP |
| 32 | * as underlying transport mechanism and is used for |
| 33 | * local communication (can enable LocalControlHeader) |
| 34 | */ |
| 35 | class TcpLocalFace : public StreamFace<boost::asio::ip::tcp, LocalFace> |
| 36 | { |
| 37 | public: |
| 38 | typedef boost::asio::ip::tcp protocol; |
| 39 | |
| 40 | explicit |
| 41 | TcpLocalFace(const shared_ptr<protocol::socket>& socket); |
| 42 | }; |
| 43 | |
Alexander Afanasyev | 232c987 | 2014-02-20 17:33:00 -0800 | [diff] [blame] | 44 | |
| 45 | /** \brief Class validating use of TcpLocalFace |
| 46 | */ |
| 47 | template<> |
| 48 | struct StreamFaceValidator<boost::asio::ip::tcp, LocalFace> |
| 49 | { |
| 50 | /** Check that local endpoint is loopback |
| 51 | * |
| 52 | * @throws Face::Error if validation failed |
| 53 | */ |
| 54 | static void |
| 55 | validateSocket(boost::asio::ip::tcp::socket& socket) |
| 56 | { |
Alexander Afanasyev | bfd31de | 2014-02-26 13:20:08 -0800 | [diff] [blame^] | 57 | if (!socket.local_endpoint().address().is_loopback() || |
| 58 | !socket.remote_endpoint().address().is_loopback()) |
Alexander Afanasyev | 232c987 | 2014-02-20 17:33:00 -0800 | [diff] [blame] | 59 | { |
| 60 | throw Face::Error("TcpLocalFace can be created only on loopback interface"); |
| 61 | } |
| 62 | } |
| 63 | }; |
| 64 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 65 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 66 | } // namespace nfd |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 67 | |
| 68 | #endif // NFD_FACE_TCP_FACE_HPP |