blob: b74380ee0f3a42e88ce4a9dc206e1b3aa51520e3 [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
Davide Pesaventod8d4d982014-03-21 18:47:58 +010012namespace nfd {
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080013
14/**
15 * \brief Implementation of Face abstraction that uses TCP
16 * as underlying transport mechanism
17 */
18class TcpFace : public StreamFace<boost::asio::ip::tcp>
19{
20public:
Davide Pesaventobc4dd8c2014-02-14 20:01:01 +010021 explicit
Alexander Afanasyev355c0662014-03-20 18:08:17 -070022 TcpFace(const shared_ptr<protocol::socket>& socket, bool isOnDemand);
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080023};
24
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080025//
26
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080027/**
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 */
32class TcpLocalFace : public StreamFace<boost::asio::ip::tcp, LocalFace>
33{
34public:
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080035 explicit
Alexander Afanasyev355c0662014-03-20 18:08:17 -070036 TcpLocalFace(const shared_ptr<protocol::socket>& socket, bool isOnDemand);
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080037};
38
Alexander Afanasyev232c9872014-02-20 17:33:00 -080039
40/** \brief Class validating use of TcpLocalFace
41 */
42template<>
43struct 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 Afanasyevbfd31de2014-02-26 13:20:08 -080052 if (!socket.local_endpoint().address().is_loopback() ||
53 !socket.remote_endpoint().address().is_loopback())
Alexander Afanasyev232c9872014-02-20 17:33:00 -080054 {
55 throw Face::Error("TcpLocalFace can be created only on loopback interface");
56 }
57 }
58};
59
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080060} // namespace nfd
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080061
62#endif // NFD_FACE_TCP_FACE_HPP