1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef REMOTING_TEST_FAKE_NETWORK_DISPATCHER_H_
6 #define REMOTING_TEST_FAKE_NETWORK_DISPATCHER_H_
10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/synchronization/lock.h"
13 #include "third_party/webrtc/p2p/base/packetsocketfactory.h"
16 class SingleThreadTaskRunner
;
25 class FakeNetworkDispatcher
26 : public base::RefCountedThreadSafe
<FakeNetworkDispatcher
> {
32 // Return thread on which ReceivePacket() should be called.
33 virtual const scoped_refptr
<base::SingleThreadTaskRunner
>& GetThread()
35 virtual const rtc::IPAddress
& GetAddress() const = 0;
37 // Deliver a packet sent by a different node.
38 virtual void ReceivePacket(const rtc::SocketAddress
& from
,
39 const rtc::SocketAddress
& to
,
40 const scoped_refptr
<net::IOBuffer
>& data
,
44 FakeNetworkDispatcher();
46 rtc::IPAddress
AllocateAddress();
48 // Must be called on the thread that the |node| works on.
49 void AddNode(Node
* node
);
50 void RemoveNode(Node
* node
);
52 void DeliverPacket(const rtc::SocketAddress
& from
,
53 const rtc::SocketAddress
& to
,
54 const scoped_refptr
<net::IOBuffer
>& data
,
58 typedef std::map
<rtc::IPAddress
, Node
*> NodesMap
;
60 friend class base::RefCountedThreadSafe
<FakeNetworkDispatcher
>;
61 virtual ~FakeNetworkDispatcher();
64 base::Lock nodes_lock_
;
66 // A counter used to allocate unique addresses in AllocateAddress().
67 int allocated_address_
;
69 DISALLOW_COPY_AND_ASSIGN(FakeNetworkDispatcher
);
72 } // namespace remoting
74 #endif // REMOTING_TEST_FAKE_NETWORK_DISPATCHER_H_