Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
bbb7839a
Commit
bbb7839a
authored
Nov 19, 2016
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle udp client handshake
parent
bf227239
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
16 deletions
+94
-16
libcaf_io/caf/io/basp/instance.hpp
libcaf_io/caf/io/basp/instance.hpp
+5
-1
libcaf_io/src/default_multiplexer.cpp
libcaf_io/src/default_multiplexer.cpp
+18
-4
libcaf_io/src/instance.cpp
libcaf_io/src/instance.cpp
+71
-11
No files found.
libcaf_io/caf/io/basp/instance.hpp
View file @
bbb7839a
...
...
@@ -198,9 +198,13 @@ public:
void
write_client_handshake
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
const
node_id
&
remote_side
);
/// Start handshake ...
/// Start handshake ...
TODO
void
write_udp_client_handshake
(
execution_unit
*
ctx
,
buffer_type
&
buf
);
/// Answer client handshake ... TODO
void
write_udp_server_handshake
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
const
node_id
&
remote_side
);
/// Writes an `announce_proxy` to `buf`.
void
write_announce_proxy
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
const
node_id
&
dest_node
,
actor_id
aid
);
...
...
libcaf_io/src/default_multiplexer.cpp
View file @
bbb7839a
...
...
@@ -1254,6 +1254,13 @@ bool send_datagram(size_t& result, native_socket fd, void* buf, size_t buf_len,
auto
sres
=
::
sendto
(
fd
,
reinterpret_cast
<
socket_send_ptr
>
(
buf
),
buf_len
,
no_sigpipe_flag
,
reinterpret_cast
<
sockaddr
*>
(
&
sa
),
sa_len
);
{
std
::
string
host
;
uint16_t
port
;
std
::
tie
(
host
,
port
)
=
sender_from_sockaddr
(
sa
,
sa_len
);
std
::
cerr
<<
"[SD] Sent "
<<
sres
<<
" bytes to "
<<
host
<<
":"
<<
port
<<
std
::
endl
;
}
if
(
is_error
(
sres
,
true
))
{
CAF_LOG_ERROR
(
"sendto returned"
<<
CAF_ARG
(
sres
));
return
false
;
...
...
@@ -1263,12 +1270,19 @@ bool send_datagram(size_t& result, native_socket fd, void* buf, size_t buf_len,
}
bool
receive_datagram
(
size_t
&
result
,
native_socket
fd
,
void
*
buf
,
size_t
len
,
sockaddr_storage
&
s
ender_addr
,
socklen_t
&
sender
_len
)
{
sockaddr_storage
&
s
a
,
socklen_t
&
sa
_len
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
fd
));
s
ender
_len
=
sizeof
(
sockaddr
);
s
a
_len
=
sizeof
(
sockaddr
);
auto
sres
=
::
recvfrom
(
fd
,
buf
,
len
,
0
,
reinterpret_cast
<
struct
sockaddr
*>
(
&
sender_addr
),
&
sender_len
);
reinterpret_cast
<
struct
sockaddr
*>
(
&
sa
),
&
sa_len
);
{
std
::
string
host
;
uint16_t
port
;
std
::
tie
(
host
,
port
)
=
sender_from_sockaddr
(
sa
,
sa_len
);
std
::
cerr
<<
"[SD] Received "
<<
sres
<<
" bytes from "
<<
host
<<
":"
<<
port
<<
std
::
endl
;
}
// TODO: Check if sres > len and do some error handling ...
if
(
is_error
(
sres
,
true
))
{
CAF_LOG_ERROR
(
"recvfrom returned"
<<
CAF_ARG
(
sres
));
...
...
libcaf_io/src/instance.cpp
View file @
bbb7839a
...
...
@@ -281,13 +281,23 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) {
std
::
cerr
<<
"Received invalid header!"
<<
std
::
endl
;
return
err
();
}
CAF_LOG_DEBUG
(
CAF_ARG
(
hdr
));
std
::
vector
<
char
>*
payload
=
nullptr
;
if
(
hdr
.
payload_len
>
0
)
{
// TODO: handle payload
payload
=
&
pl_buf
;
if
(
payload
->
size
()
!=
hdr
.
payload_len
)
{
CAF_LOG_WARNING
(
"received invalid payload"
);
std
::
cerr
<<
"Received invalid payload"
<<
std
::
endl
;
return
err
();
}
CAF_LOG_DEBUG
(
CAF_ARG
(
hdr
));
/*
std
::
cerr
<<
"Received "
<<
payload
->
size
()
<<
" bytes payload."
<<
std
::
endl
;
}
// TODO: handle payload
// needs forwarding?
if
(
!
is_handshake
(
hdr
)
&&
!
is_heartbeat
(
hdr
)
&&
hdr
.
dest_node
!=
this_node_
)
{
std
::
cerr
<<
"[I] Needs forwarding?"
<<
std
::
endl
;
/*
CAF_LOG_DEBUG("forward message");
auto path = lookup(hdr.dest_node);
if (path) {
...
...
@@ -315,24 +325,23 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) {
notify<hook::message_forwarding_failed>(hdr, payload);
}
return await_header;
*/
}
// function object for checking payload validity
auto
payload_valid
=
[
&
]()
->
bool
{
return
payload
!=
nullptr
&&
payload
->
size
()
==
hdr
.
payload_len
;
};
*/
// handle message to ourselves
switch
(
hdr
.
operation
)
{
case
message_type
:
:
udp_server_handshake
:
{
std
::
cerr
<<
"[I]
message_type::udp_server_
handshake"
<<
std
::
endl
;
std
::
cerr
<<
"[I]
Received UDP server
handshake"
<<
std
::
endl
;
break
;
}
case
message_type
:
:
udp_client_handshake
:
{
std
::
cerr
<<
"[I]
message_type::udp_client_
handshake"
<<
std
::
endl
;
std
::
cerr
<<
"[I]
Received UDP client
handshake"
<<
std
::
endl
;
// udp scribes start with a client handshake when sending the first
// message, should be answered by a server handshake!
/*
actor_id
aid
=
invalid_actor_id
;
std
::
set
<
std
::
string
>
sigs
;
if
(
payload_valid
())
{
...
...
@@ -343,6 +352,7 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) {
return
err
();
if
(
remote_appid
!=
callee_
.
system
().
config
().
middleman_app_identifier
)
{
CAF_LOG_ERROR
(
"app identifier mismatch"
);
std
::
cerr
<<
"app identifier mismatch"
<<
std
::
endl
;
return
err
();
}
e
=
bd
(
aid
,
sigs
);
...
...
@@ -350,11 +360,13 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) {
return
err
();
}
else
{
CAF_LOG_ERROR
(
"fail to receive the app identifier"
);
std
::
cerr
<<
"fail to receive the app identifier"
<<
std
::
endl
;
return
err
();
}
// close self connection after handshake is done
if
(
hdr
.
source_node
==
this_node_
)
{
CAF_LOG_INFO
(
"close connection to self immediately"
);
std
::
cerr
<<
"close connection to self immediately"
<<
std
::
endl
;
callee_
.
finalize_handshake
(
hdr
.
source_node
,
aid
,
sigs
);
return
err
();
}
...
...
@@ -362,11 +374,16 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) {
if
(
tbl_
.
lookup_hdl
(
hdr
.
source_node
))
{
CAF_LOG_INFO
(
"close connection since we already have a "
"direct connection: "
<<
CAF_ARG
(
hdr
.
source_node
));
std
::
cerr
<<
"close connection since we already have a "
"direct connection: "
<<
to_string
(
hdr
.
source_node
)
<<
std
::
endl
;
callee_
.
finalize_handshake
(
hdr
.
source_node
,
aid
,
sigs
);
return
err
();
}
// add direct route to this node and remove any indirect entry
CAF_LOG_INFO
(
"new direct connection:"
<<
CAF_ARG
(
hdr
.
source_node
));
std
::
cerr
<<
"new direct connection: "
<<
to_string
(
hdr
.
source_node
)
<<
std
::
endl
;
tbl_
.
add
(
dm
.
handle
,
hdr
.
source_node
);
// auto was_indirect = tbl_.erase_indirect(hdr.source_node);
// write handshake as client in response
...
...
@@ -375,11 +392,10 @@ bool instance::handle(execution_unit* ctx, new_datagram_msg& dm, header& hdr) {
CAF_LOG_ERROR
(
"no route to host after server handshake"
);
return
err
();
}
write_
client
_handshake(ctx, path->wr_buf, hdr.source_node);
write_
udp_server
_handshake
(
ctx
,
path
->
wr_buf
,
hdr
.
source_node
);
callee_
.
learned_new_node_directly
(
hdr
.
source_node
);
callee_
.
finalize_handshake
(
hdr
.
source_node
,
aid
,
sigs
);
flush
(
*
path
);
*/
break
;
}
case
message_type
:
:
server_handshake
:
{
...
...
@@ -740,9 +756,53 @@ void instance::write_client_handshake(execution_unit* ctx,
void
instance
::
write_udp_client_handshake
(
execution_unit
*
ctx
,
buffer_type
&
buf
)
{
CAF_LOG_TRACE
(
""
);
/*
CAF_LOG_TRACE(CAF_ARG(port));
using namespace detail;
published_actor* pa = nullptr;
if (port) {
auto i = published_actors_.find(*port);
if (i != published_actors_.end())
pa = &i->second;
}
CAF_LOG_DEBUG_IF(!pa && port, "no actor published");
if (!pa && port) {
std::cerr << "No actor published." << std::endl;
} else {
std::cerr << "Found locally published actor." << std::endl;
}
*/
auto
writer
=
make_callback
([
&
](
serializer
&
sink
)
->
error
{
auto
&
ref
=
callee_
.
system
().
config
().
middleman_app_identifier
;
auto
e
=
sink
(
const_cast
<
std
::
string
&>
(
ref
));
if
(
e
)
return
e
;
//if (pa) {
// auto i = pa->first ? pa->first->id() : invalid_actor_id;
// return sink(i, pa->second);
//} else {
auto
aid
=
invalid_actor_id
;
std
::
set
<
std
::
string
>
tmp
;
return
sink
(
aid
,
tmp
);
//}
});
header
hdr
{
message_type
::
udp_client_handshake
,
0
,
0
,
version
,
this_node_
,
none
,
invalid_actor_id
,
invalid_actor_id
};
write
(
ctx
,
buf
,
hdr
);
write
(
ctx
,
buf
,
hdr
,
&
writer
);
}
void
instance
::
write_udp_server_handshake
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
const
node_id
&
remote_side
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
remote_side
));
auto
writer
=
make_callback
([
&
](
serializer
&
sink
)
->
error
{
auto
&
str
=
callee_
.
system
().
config
().
middleman_app_identifier
;
return
sink
(
const_cast
<
std
::
string
&>
(
str
));
});
header
hdr
{
message_type
::
udp_server_handshake
,
0
,
0
,
0
,
this_node_
,
remote_side
,
invalid_actor_id
,
invalid_actor_id
};
write
(
ctx
,
buf
,
hdr
,
&
writer
);
}
void
instance
::
write_announce_proxy
(
execution_unit
*
ctx
,
buffer_type
&
buf
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment