Skip to content

Commit

Permalink
added rdp_get_status to get status of RDP
Browse files Browse the repository at this point in the history
  • Loading branch information
ytakano committed Apr 14, 2011
1 parent e236db1 commit 1b2ead5
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 26 deletions.
2 changes: 1 addition & 1 deletion OMakefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ uninstall:
# If so, define the subdirectory targets and uncomment this section.
#

.SUBDIRS: src sample test
.SUBDIRS: src example test


########################################################################
Expand Down
20 changes: 20 additions & 0 deletions example/OMakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CXXFLAGS += -Wall -I../include
LDFLAGS += -lcrypto
LIBS += ../src/libcage


.PHONY: clean example1 example2 example3 example4 example5 caged

example1: $(CXXProgram example1, example1)
example2: $(CXXProgram example2, example2)
example2: $(CXXProgram example3, example3)
example4: $(CXXProgram example4, example4)
example4: $(CXXProgram example5, example5)

caged: $(CXXProgram caged, caged)

clean:
rm -f *~ *.o
rm -f example1 example2 example3 example4 example5 caged

.DEFAULT: example1 example2 example3 example4 example5 caged
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 0 additions & 20 deletions sample/OMakefile

This file was deleted.

10 changes: 8 additions & 2 deletions src/cage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,15 @@ namespace libcage {
}

rdp_state
cage::rdp_status(int desc)
cage::rdp_get_desc_state(int desc)
{
return m_rdp.status(desc);
return m_rdp.get_desc_state(desc);
}

void
cage::rdp_get_status(std::vector<rdp_status> &vec)
{
return m_rdp.get_status(vec);
}

void
Expand Down
3 changes: 2 additions & 1 deletion src/cage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ namespace libcage {
void rdp_close(int desc);
int rdp_send(int desc, const void *buf, int len);
void rdp_receive(int desc, void *buf, int *len);
rdp_state rdp_status(int desc);
rdp_state rdp_get_desc_state(int desc);
void rdp_get_status(std::vector<rdp_status> &vec);


void send_dgram(const void *buf, int len,
Expand Down
1 change: 1 addition & 0 deletions src/cagetypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace libcage {
typedef boost::shared_ptr<sockaddr_in> in_ptr;
typedef boost::shared_ptr<sockaddr_in6> in6_ptr;
typedef boost::shared_ptr<uint160_t> id_ptr;
typedef boost::shared_ptr<const uint160_t> id_const_ptr;

typedef boost::uniform_int<uint32_t> uint_dist;
typedef boost::uniform_real<> real_dist;
Expand Down
45 changes: 44 additions & 1 deletion src/rdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ namespace libcage {
}

rdp_state
rdp::status(int desc)
rdp::get_desc_state(int desc)
{
if (m_desc_set.find(desc) == m_desc_set.end())
return CLOSED;
Expand Down Expand Up @@ -1913,4 +1913,47 @@ namespace libcage {

acked_time.update();
}

void
rdp::get_status(std::vector<rdp_status> &vec)
{
id_ptr zero(new uint160_t);

zero->fill_zero();

BOOST_FOREACH(int desc, m_desc_set) {
listening_t::right_iterator lis_it;
lis_it = m_listening.right.find(desc);

if (lis_it != m_listening.right.end()) {
rdp_status s;

s.state = LISTEN;
s.did = zero;
s.dport = 0;
s.sport = lis_it->second;

vec.push_back(s);

continue;
}


std::map<int, rdp_con_ptr>::iterator conn_it;
conn_it = m_desc2conn.find(desc);

if (conn_it != m_desc2conn.end()) {
rdp_status s;

s.state = conn_it->second->state;
s.did = conn_it->second->addr.did;
s.dport = conn_it->second->addr.dport;
s.sport = conn_it->second->addr.sport;

vec.push_back(s);

continue;
}
}
}
}
10 changes: 9 additions & 1 deletion src/rdp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ namespace libcage {
}
};

struct rdp_status {
rdp_state state;
id_const_ptr did;
uint16_t dport;
uint16_t sport;
};

size_t hash_value(const rdp_addr &addr);

typedef boost::function<void (id_ptr, packetbuf_ptr)> callback_dgram_out;
Expand Down Expand Up @@ -146,7 +153,8 @@ namespace libcage {
void close(int desc);
int send(int desc, const void *buf, int len);
void receive(int desc, void *buf, int *len);
rdp_state status(int desc);
rdp_state get_desc_state(int desc);
void get_status(std::vector<rdp_status> &vec);

void set_callback_rdp_event(int desc,
callback_rdp_event func);
Expand Down

0 comments on commit 1b2ead5

Please sign in to comment.