blob: dfd60280675de7e49741c36c5eea631cf97705fe [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
Junxiao Shi8c8d2182014-01-30 22:33:00 -070025 TcpFace(const shared_ptr<protocol::socket>& socket);
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080026};
27
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080028//
29
30/** \brief Class validating use of TcpLocalFace
31 */
32template<>
33struct StreamFaceValidator<boost::asio::ip::tcp, LocalFace>
34{
35 /** Check that local endpoint is loopback
36 *
37 * @throws Face::Error if validation failed
38 */
39 static void
40 validateSocket(boost::asio::ip::tcp::socket& socket)
41 {
42 if (!socket.local_endpoint().address().is_loopback() ||
43 !socket.remote_endpoint().address().is_loopback())
44 {
45 throw Face::Error("TcpLocalFace can be created only on loopback interface");
46 }
47 }
48};
49
50/**
51 * \brief Implementation of Face abstraction that uses TCP
52 * as underlying transport mechanism and is used for
53 * local communication (can enable LocalControlHeader)
54 */
55class TcpLocalFace : public StreamFace<boost::asio::ip::tcp, LocalFace>
56{
57public:
58 typedef boost::asio::ip::tcp protocol;
59
60 explicit
61 TcpLocalFace(const shared_ptr<protocol::socket>& socket);
62};
63
64
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080065} // namespace nfd
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080066
67#endif // NFD_FACE_TCP_FACE_HPP