⚲
Project
General
Profile
Sign in
Register
Home
Projects
Search
:
ndn-tools
All Projects
NFD
»
ndn-tools
Overview
Activity
Issues
Download (1.37 KB)
Bug #3263
ยป producer-nack.cpp
Teng Liang
, 03/17/2016 11:19 AM
#include
"face.hpp"
#include
"security/key-chain.hpp"
#include
"lp/nack.hpp"
namespace
ndn
{
namespace
examples
{
class
Producer
:
noncopyable
{
public:
void
run
()
{
m_face
.
setInterestFilter
(
"/"
,
bind
(
&
Producer
::
onInterest
,
this
,
_1
,
_2
),
RegisterPrefixSuccessCallback
(),
bind
(
&
Producer
::
onRegisterFailed
,
this
,
_1
,
_2
));
m_face
.
processEvents
();
}
private:
void
onInterest
(
const
InterestFilter
&
filter
,
const
Interest
&
interest
)
{
std
::
cout
<<
"<< I: "
<<
interest
<<
std
::
endl
;
shared_ptr
<
lp
::
Nack
>
nack
=
make_shared
<
lp
::
Nack
>
(
interest
);
lp
::
NackHeader
header
;
header
.
setReason
(
lp
::
NackReason
::
CONGESTION
);
nack
->
setHeader
(
header
);
std
::
cout
<<
">> N: "
<<
std
::
endl
;
m_face
.
put
(
*
nack
);
}
void
onRegisterFailed
(
const
Name
&
prefix
,
const
std
::
string
&
reason
)
{
std
::
cerr
<<
"ERROR: Failed to register prefix
\"
"
<<
prefix
<<
"
\"
in local hub's daemon ("
<<
reason
<<
")"
<<
std
::
endl
;
m_face
.
shutdown
();
}
private:
Face
m_face
;
KeyChain
m_keyChain
;
};
}
// namespace examples
}
// namespace ndn
int
main
(
int
argc
,
char
**
argv
)
{
ndn
::
examples
::
Producer
producer
;
try
{
producer
.
run
();
}
catch
(
const
std
::
exception
&
e
)
{
std
::
cerr
<<
"ERROR: "
<<
e
.
what
()
<<
std
::
endl
;
}
return
0
;
}
(1-1/1)
Loading...