blob: 92ab6273ff0af7b795fcba7d195bffb56dad65e0 [file] [log] [blame]
Alexander Afanasyeva9034b02014-01-26 18:32:02 -08001/* -*- 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 Afanasyev18bbf812014-01-29 01:40:23 -080012namespace nfd
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080013{
14
15/**
16 * \brief Implementation of Face abstraction that uses TCP
17 * as underlying transport mechanism
18 */
19class TcpFace : public StreamFace<boost::asio::ip::tcp>
20{
21public:
Alexander Afanasyevd32cb962014-01-28 12:43:47 -080022 typedef boost::asio::ip::tcp protocol;
23
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010024 explicit
Alexander Afanasyev355c0662014-03-20 18:08:17 -070025 TcpFace(const shared_ptr<protocol::socket>& socket, bool isOnDemand);
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080026};
27
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080028//
29
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080030/**
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 */
35class TcpLocalFace : public StreamFace<boost::asio::ip::tcp, LocalFace>
36{
37public:
38 typedef boost::asio::ip::tcp protocol;
39
40 explicit
Alexander Afanasyev355c0662014-03-20 18:08:17 -070041 TcpLocalFace(const shared_ptr<protocol::socket>& socket, bool isOnDemand);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080042};
43
Alexander Afanasyev232c9872014-02-20 17:33:00 -080044
45/** \brief Class validating use of TcpLocalFace
46 */
47template<>
48struct 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 Afanasyevbfd31de2014-02-26 13:20:08 -080057 if (!socket.local_endpoint().address().is_loopback() ||
58 !socket.remote_endpoint().address().is_loopback())
Alexander Afanasyev232c9872014-02-20 17:33:00 -080059 {
60 throw Face::Error("TcpLocalFace can be created only on loopback interface");
61 }
62 }
63};
64
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080065
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080066} // namespace nfd
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080067
68#endif // NFD_FACE_TCP_FACE_HPP