mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-15 15:41:24 +01:00
add and handle new INVITE message types. (This can safely be added to shipping relay.)
This commit is contained in:
parent
1b6ce4861f
commit
0102cde2c3
2 changed files with 43 additions and 4 deletions
|
@ -374,10 +374,15 @@ getHeader( const uint8_t** bufpp, const uint8_t* end,
|
|||
uint8_t byt;
|
||||
if ( getNetByte( bufpp, end, &byt ) ) {
|
||||
header->proto = (XWPDevProto)byt;
|
||||
if ( XWPDEV_PROTO_VERSION_1 == header->proto
|
||||
&& vli2un( bufpp, end, &header->packetID )
|
||||
&& getNetByte( bufpp, end, &byt )
|
||||
&& byt < XWPDEV_N_ELEMS ) {
|
||||
if ( XWPDEV_PROTO_VERSION_1 != header->proto ) {
|
||||
logf( XW_LOGERROR, "%s: bad proto %d", __func__, header->proto );
|
||||
} else if ( !vli2un( bufpp, end, &header->packetID ) ) {
|
||||
logf( XW_LOGERROR, "%s: can't get packet id", __func__ );
|
||||
} else if ( !getNetByte( bufpp, end, &byt ) ) {
|
||||
logf( XW_LOGERROR, "%s: can't get cmd", __func__ );
|
||||
} else if ( XWPDEV_N_ELEMS <= byt ) {
|
||||
logf( XW_LOGERROR, "%s: cmd %d too high", __func__, byt );
|
||||
} else {
|
||||
header->cmd = (XWRelayReg)byt;
|
||||
success = true;
|
||||
}
|
||||
|
@ -838,6 +843,22 @@ post_upgrade( DevIDRelay devid )
|
|||
(void)post_or_store( devid, packet, packetID, NULL, NULL );
|
||||
}
|
||||
|
||||
void
|
||||
post_invite( DevIDRelay sender, DevIDRelay invitee, const uint8_t* ptr, size_t len )
|
||||
{
|
||||
vector<uint8_t> packet;
|
||||
uint32_t packetID;
|
||||
sender = htonl( sender );
|
||||
assemble_packet( packet, &packetID, XWPDEV_GOTINVITE,
|
||||
&sender, sizeof(sender),
|
||||
ptr, len,
|
||||
NULL );
|
||||
|
||||
bool sent = post_or_store( invitee, packet, packetID, NULL, NULL );
|
||||
logf( XW_LOGINFO, "%s(): post_or_store => %s", __func__,
|
||||
sent ? "sent" : "stored");
|
||||
}
|
||||
|
||||
/* A CONNECT message from a device gives us the hostID and socket we'll
|
||||
* associate with one participant in a relayed session. We'll store this
|
||||
* information with the cookie where other participants can find it when they
|
||||
|
@ -1652,6 +1673,7 @@ msgToStr( XWRelayReg msg )
|
|||
CASE_STR(XWPDEV_UNAVAIL);
|
||||
CASE_STR(XWPDEV_REG);
|
||||
CASE_STR(XWPDEV_REGRSP);
|
||||
CASE_STR(XWPDEV_INVITE);
|
||||
CASE_STR(XWPDEV_KEEPALIVE);
|
||||
CASE_STR(XWPDEV_HAVEMSGS);
|
||||
CASE_STR(XWPDEV_RQSTMSGS);
|
||||
|
@ -1756,6 +1778,18 @@ handle_udp_packet( UdpThreadClosure* utc )
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case XWPDEV_INVITE:
|
||||
DevIDRelay sender;
|
||||
DevIDRelay invitee;
|
||||
if ( getNetLong( &ptr, end, &sender )
|
||||
&& getNetLong( &ptr, end, &invitee) ) {
|
||||
logf( XW_LOGVERBOSE0, "got invite from %d for %d",
|
||||
sender, invitee );
|
||||
post_invite( sender, invitee, ptr, end - ptr );
|
||||
}
|
||||
break;
|
||||
|
||||
case XWPDEV_KEEPALIVE:
|
||||
case XWPDEV_RQSTMSGS: {
|
||||
DevID devID( ID_TYPE_RELAY );
|
||||
|
|
|
@ -108,6 +108,11 @@ enum { XWPDEV_NONE /* 0 is an illegal value */
|
|||
to check for upgrades; may eventually
|
||||
replace device needing a timer. */
|
||||
|
||||
,XWPDEV_INVITE /* dev->relay; format: header, sender relay
|
||||
id: 4, recipient relay id: 4; nli data:
|
||||
variable length. */
|
||||
,XWPDEV_GOTINVITE /* relay->dev */
|
||||
|
||||
,XWPDEV_N_ELEMS /* MUST BE LAST */
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue