manual bring-over of relay changes for invite support

This commit is contained in:
Eric House 2015-07-11 08:08:22 -07:00
parent 9c7213e42b
commit 67f4e4475c
3 changed files with 28 additions and 6 deletions

View file

@ -902,6 +902,19 @@ DBMgr::readArray( const char* const connName, const char* column, int arr[] ) /
PQclear( result );
}
// parse something created by comms.c's formatRelayID
DevIDRelay
DBMgr::getDevID( string& relayID )
{
size_t pos = relayID.find_first_of( '/' );
string connName = relayID.substr( 0, pos );
int hid = relayID[pos + 1] - '0';
DevIDRelay result = getDevID( connName.c_str(), hid );
// Not an error. Remove or downlog when confirm working
logf( XW_LOGERROR, "%s(%s) => %d", __func__, relayID.c_str(), result );
return result;
}
DevIDRelay
DBMgr::getDevID( const char* connName, int hid )
{

View file

@ -148,6 +148,8 @@ class DBMgr {
void RemoveStoredMessage( const int msgID );
void RemoveStoredMessages( vector<int>& ids );
DevIDRelay getDevID( string& relayID );
private:
DBMgr();
bool execSql( const string& query );

View file

@ -1780,17 +1780,24 @@ handle_udp_packet( UdpThreadClosure* utc )
break;
}
case XWPDEV_INVITE:
case XWPDEV_INVITE: {
DevIDRelay sender;
DevIDRelay invitee;
if ( getNetLong( &ptr, end, &sender )
&& getNetLong( &ptr, end, &invitee) ) {
string relayID;
if ( getNetLong( &ptr, end, &sender )
&& getNetString( &ptr, end, relayID ) ) {
DevIDRelay invitee;
if ( 0 < relayID.size() ) {
invitee = DBMgr::Get()->getDevID( relayID );
} else if ( !getNetLong( &ptr, end, &invitee ) ) {
break; // failure
}
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 );
@ -2048,7 +2055,7 @@ main( int argc, char** argv )
exit( 0 );
case 'b':
doBlock = true;
break;
break;
case 'c':
ctrlport = atoi( optarg );
break;