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 | |
Davide Pesavento | d8d4d98 | 2014-03-21 18:47:58 +0100 | [diff] [blame] | 12 | namespace nfd { |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 13 | |
| 14 | /** |
| 15 | * \brief Implementation of Face abstraction that uses TCP |
| 16 | * as underlying transport mechanism |
| 17 | */ |
| 18 | class TcpFace : public StreamFace<boost::asio::ip::tcp> |
| 19 | { |
| 20 | public: |
Davide Pesavento | bc4dd8c | 2014-02-14 20:01:01 +0100 | [diff] [blame] | 21 | explicit |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 22 | TcpFace(const shared_ptr<protocol::socket>& socket, bool isOnDemand); |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 23 | }; |
| 24 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 25 | // |
| 26 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 27 | /** |
| 28 | * \brief Implementation of Face abstraction that uses TCP |
| 29 | * as underlying transport mechanism and is used for |
| 30 | * local communication (can enable LocalControlHeader) |
| 31 | */ |
| 32 | class TcpLocalFace : public StreamFace<boost::asio::ip::tcp, LocalFace> |
| 33 | { |
| 34 | public: |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 35 | explicit |
Alexander Afanasyev | 355c066 | 2014-03-20 18:08:17 -0700 | [diff] [blame] | 36 | TcpLocalFace(const shared_ptr<protocol::socket>& socket, bool isOnDemand); |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 37 | }; |
| 38 | |
Alexander Afanasyev | 232c987 | 2014-02-20 17:33:00 -0800 | [diff] [blame] | 39 | |
| 40 | /** \brief Class validating use of TcpLocalFace |
| 41 | */ |
| 42 | template<> |
| 43 | struct StreamFaceValidator<boost::asio::ip::tcp, LocalFace> |
| 44 | { |
| 45 | /** Check that local endpoint is loopback |
| 46 | * |
| 47 | * @throws Face::Error if validation failed |
| 48 | */ |
| 49 | static void |
| 50 | validateSocket(boost::asio::ip::tcp::socket& socket) |
| 51 | { |
Alexander Afanasyev | bfd31de | 2014-02-26 13:20:08 -0800 | [diff] [blame] | 52 | if (!socket.local_endpoint().address().is_loopback() || |
| 53 | !socket.remote_endpoint().address().is_loopback()) |
Alexander Afanasyev | 232c987 | 2014-02-20 17:33:00 -0800 | [diff] [blame] | 54 | { |
| 55 | throw Face::Error("TcpLocalFace can be created only on loopback interface"); |
| 56 | } |
| 57 | } |
| 58 | }; |
| 59 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 60 | } // namespace nfd |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 61 | |
| 62 | #endif // NFD_FACE_TCP_FACE_HPP |