communicate variant to relay, and store in new column

This commit is contained in:
Eric House 2019-01-25 17:44:46 -08:00
parent 316bf0060b
commit a14b43bba0
6 changed files with 43 additions and 21 deletions

View file

@ -392,6 +392,7 @@ public class RelayService extends JobIntentService
} }
// NetStateCache.StateChangedIf interface // NetStateCache.StateChangedIf interface
@Override
public void onNetAvail( boolean nowAvailable ) public void onNetAvail( boolean nowAvailable )
{ {
startService( this ); // bad name: will *stop* threads too startService( this ); // bad name: will *stop* threads too
@ -759,9 +760,9 @@ public class RelayService extends JobIntentService
out.writeShort( BuildConfig.CLIENT_VERS_RELAY ); out.writeShort( BuildConfig.CLIENT_VERS_RELAY );
writeVLIString( out, BuildConfig.GIT_REV ); writeVLIString( out, BuildConfig.GIT_REV );
// writeVLIString( out, String.format( "€%s", Build.MODEL) );
writeVLIString( out, Build.MODEL ); writeVLIString( out, Build.MODEL );
writeVLIString( out, Build.VERSION.RELEASE ); writeVLIString( out, Build.VERSION.RELEASE );
writeVLIString( out, BuildConfig.VARIANT_NAME );
postPacket( bas, XWRelayReg.XWPDEV_REG ); postPacket( bas, XWRelayReg.XWPDEV_REG );
s_regStartTime = now; s_regStartTime = now;

View file

@ -305,6 +305,7 @@ relaycon_reg( LaunchParams* params, const XP_UCHAR* rDevID,
indx += addVLIStr( &tmpbuf[indx], sizeof(tmpbuf) - indx, SVN_REV ); indx += addVLIStr( &tmpbuf[indx], sizeof(tmpbuf) - indx, SVN_REV );
indx += addVLIStr( &tmpbuf[indx], sizeof(tmpbuf) - indx, "linux box" ); indx += addVLIStr( &tmpbuf[indx], sizeof(tmpbuf) - indx, "linux box" );
indx += addVLIStr( &tmpbuf[indx], sizeof(tmpbuf) - indx, "linux version" ); indx += addVLIStr( &tmpbuf[indx], sizeof(tmpbuf) - indx, "linux version" );
indx += addVLIStr( &tmpbuf[indx], sizeof(tmpbuf) - indx, "linux variant" );
sendIt( storage, tmpbuf, indx, 0.5 ); sendIt( storage, tmpbuf, indx, 0.5 );
} }

View file

@ -276,7 +276,7 @@ DBMgr::FindRelayIDFor( const char* connName, HostID hid,
if ( found ) { if ( found ) {
devID = (DevIDRelay)strtoul( PQgetvalue( result, 0, 0 ), NULL, 10 ); devID = (DevIDRelay)strtoul( PQgetvalue( result, 0, 0 ), NULL, 10 );
*devIDP = devID; *devIDP = devID;
ReregisterDevice( devID, host, NULL, 0, NULL, NULL ); ReregisterDevice( devID, host, NULL, 0, NULL, NULL, NULL );
} }
PQclear( result ); PQclear( result );
if ( !found ) { if ( !found ) {
@ -390,7 +390,7 @@ DBMgr::AllDevsAckd( const char* const connName )
DevIDRelay DevIDRelay
DBMgr::RegisterDevice( const DevID* host, int clientVersion, DBMgr::RegisterDevice( const DevID* host, int clientVersion,
const char* const desc, const char* const model, const char* const desc, const char* const model,
const char* const osVers ) const char* const osVers, const char* const variant )
{ {
DevIDRelay devID; DevIDRelay devID;
assert( host->m_devIDType != ID_TYPE_NONE ); assert( host->m_devIDType != ID_TYPE_NONE );
@ -418,8 +418,8 @@ DBMgr::RegisterDevice( const DevID* host, int clientVersion,
QueryBuilder qb; QueryBuilder qb;
qb.appendQueryf( "INSERT INTO " DEVICES_TABLE " (id, devTypes[1]," qb.appendQueryf( "INSERT INTO " DEVICES_TABLE " (id, devTypes[1],"
" devids[1], clntVers, versdesc, model, osvers)" " devids[1], clntVers, versdesc, model, osvers, variant)"
" VALUES($$, $$, $$, $$, $$, $$, $$)" ) " VALUES($$, $$, $$, $$, $$, $$, $$, $$)" )
.appendParam( devID ) .appendParam( devID )
.appendParam( host->m_devIDType ) .appendParam( host->m_devIDType )
@ -428,6 +428,7 @@ DBMgr::RegisterDevice( const DevID* host, int clientVersion,
.appendParam( desc ) .appendParam( desc )
.appendParam( model ) .appendParam( model )
.appendParam( osVers ) .appendParam( osVers )
.appendParam( variant )
.finish(); .finish();
success = execParams( qb ); success = execParams( qb );
@ -439,13 +440,14 @@ DBMgr::RegisterDevice( const DevID* host, int clientVersion,
DevIDRelay DevIDRelay
DBMgr::RegisterDevice( const DevID* host ) DBMgr::RegisterDevice( const DevID* host )
{ {
return RegisterDevice( host, 0, NULL, NULL, NULL ); return RegisterDevice( host, 0, NULL, NULL, NULL, NULL );
} }
void void
DBMgr::ReregisterDevice( DevIDRelay relayID, const DevID* host, DBMgr::ReregisterDevice( DevIDRelay relayID, const DevID* host,
const char* const desc, int clientVersion, const char* const desc, int clientVersion,
const char* const model, const char* const osVers ) const char* const model, const char* const osVers,
const char* const variant )
{ {
QueryBuilder qb; QueryBuilder qb;
qb.appendQueryf( "UPDATE " DEVICES_TABLE " SET " qb.appendQueryf( "UPDATE " DEVICES_TABLE " SET "
@ -455,7 +457,7 @@ DBMgr::ReregisterDevice( DevIDRelay relayID, const DevID* host,
.appendParam( host->m_devIDType ) .appendParam( host->m_devIDType )
.appendParam( host->m_devIDString.c_str() ); .appendParam( host->m_devIDString.c_str() );
formatUpdate( qb, true, desc, clientVersion, model, osVers, relayID ); formatUpdate( qb, true, desc, clientVersion, model, osVers, variant, relayID );
qb.finish(); qb.finish();
execParams( qb ); execParams( qb );
} }
@ -464,7 +466,8 @@ DBMgr::ReregisterDevice( DevIDRelay relayID, const DevID* host,
bool bool
DBMgr::UpdateDevice( DevIDRelay relayID, const char* const desc, DBMgr::UpdateDevice( DevIDRelay relayID, const char* const desc,
int clientVersion, const char* const model, int clientVersion, const char* const model,
const char* const osVers, bool check ) const char* const osVers, const char* const variant,
bool check )
{ {
bool exists = !check; bool exists = !check;
if ( !exists ) { if ( !exists ) {
@ -476,7 +479,8 @@ DBMgr::UpdateDevice( DevIDRelay relayID, const char* const desc,
if ( exists ) { if ( exists ) {
QueryBuilder qb; QueryBuilder qb;
qb.appendQueryf( "UPDATE " DEVICES_TABLE " SET " ); qb.appendQueryf( "UPDATE " DEVICES_TABLE " SET " );
formatUpdate( qb, false, desc, clientVersion, model, osVers, relayID ); formatUpdate( qb, false, desc, clientVersion, model, osVers,
variant, relayID );
qb.finish(); qb.finish();
execParams( qb ); execParams( qb );
} }
@ -486,14 +490,15 @@ DBMgr::UpdateDevice( DevIDRelay relayID, const char* const desc,
bool bool
DBMgr::UpdateDevice( DevIDRelay relayID ) DBMgr::UpdateDevice( DevIDRelay relayID )
{ {
return UpdateDevice( relayID, NULL, 0, NULL, NULL, false ); return UpdateDevice( relayID, NULL, 0, NULL, NULL, NULL, false );
} }
void void
DBMgr::formatUpdate( QueryBuilder& qb, DBMgr::formatUpdate( QueryBuilder& qb,
bool append, const char* const desc, bool append, const char* const desc,
int clientVersion, const char* const model, int clientVersion, const char* const model,
const char* const osVers, DevIDRelay relayID ) const char* const osVers, const char* const variant,
DevIDRelay relayID )
{ {
if ( append ) { if ( append ) {
qb.appendQueryf( "mtimes=array_prepend('now', mtimes)" ); // FIXME: too many qb.appendQueryf( "mtimes=array_prepend('now', mtimes)" ); // FIXME: too many
@ -515,6 +520,10 @@ DBMgr::formatUpdate( QueryBuilder& qb,
qb.appendQueryf( ", osvers=$$" ) qb.appendQueryf( ", osvers=$$" )
.appendParam( osVers ); .appendParam( osVers );
} }
if ( NULL != variant && '\0' != variant[0] ) {
qb.appendQueryf( ", variant=$$" )
.appendParam( variant );
}
qb.appendQueryf( " WHERE id = $$" ) qb.appendQueryf( " WHERE id = $$" )
.appendParam( relayID ); .appendParam( relayID );
} }

View file

@ -101,13 +101,15 @@ class DBMgr {
DevIDRelay RegisterDevice( const DevID* host ); DevIDRelay RegisterDevice( const DevID* host );
DevIDRelay RegisterDevice( const DevID* host, int clientVersion, DevIDRelay RegisterDevice( const DevID* host, int clientVersion,
const char* const desc, const char* const model, const char* const desc, const char* const model,
const char* const osVers ); const char* const osVers, const char* const variant );
void ReregisterDevice( DevIDRelay relayID, const DevID* host, void ReregisterDevice( DevIDRelay relayID, const DevID* host,
const char* const desc, int clientVersion, const char* const desc, int clientVersion,
const char* const model, const char* const osVers ); const char* const model, const char* const osVers,
const char* const variant );
bool UpdateDevice( DevIDRelay relayID, const char* const desc, bool UpdateDevice( DevIDRelay relayID, const char* const desc,
int clientVersion, const char* const model, int clientVersion, const char* const model,
const char* const osVers, bool check ); const char* const osVers, const char* const variant,
bool check );
HostID AddToGame( const char* const connName, HostID curID, int clientVersion, HostID AddToGame( const char* const connName, HostID curID, int clientVersion,
int nToAdd, unsigned short seed, const AddrInfo* addr, int nToAdd, unsigned short seed, const AddrInfo* addr,
@ -174,7 +176,8 @@ class DBMgr {
bool UpdateDevice( DevIDRelay relayID ); bool UpdateDevice( DevIDRelay relayID );
void formatUpdate( QueryBuilder& qb, bool append, const char* const desc, void formatUpdate( QueryBuilder& qb, bool append, const char* const desc,
int clientVersion, const char* const model, int clientVersion, const char* const model,
const char* const osVers, DevIDRelay relayID ); const char* const osVers, const char* const variant,
DevIDRelay relayID );
PGconn* getThreadConn( void ); PGconn* getThreadConn( void );

View file

@ -1598,7 +1598,8 @@ addRegID( uint8_t* ptr, DevIDRelay relayID )
static void static void
registerDevice( const string& relayIDStr, const DevID* devID, registerDevice( const string& relayIDStr, const DevID* devID,
const AddrInfo* addr, int clientVers, const string& devDesc, const AddrInfo* addr, int clientVers, const string& devDesc,
const string& model, const string& osVers ) const string& model, const string& osVers,
const string& variant )
{ {
DevIDRelay relayID = DBMgr::DEVID_NONE; DevIDRelay relayID = DBMgr::DEVID_NONE;
DBMgr* dbMgr = DBMgr::Get(); DBMgr* dbMgr = DBMgr::Get();
@ -1610,15 +1611,16 @@ registerDevice( const string& relayIDStr, const DevID* devID,
if ( DBMgr::DEVID_NONE == relayID ) { // new device if ( DBMgr::DEVID_NONE == relayID ) { // new device
relayID = dbMgr->RegisterDevice( devID, clientVers, devDesc.c_str(), relayID = dbMgr->RegisterDevice( devID, clientVers, devDesc.c_str(),
model.c_str(), osVers.c_str() ); model.c_str(), osVers.c_str(), variant.c_str() );
} else if ( ID_TYPE_RELAY < devID->m_devIDType ) { // re-registering } else if ( ID_TYPE_RELAY < devID->m_devIDType ) { // re-registering
dbMgr->ReregisterDevice( relayID, devID, devDesc.c_str(), clientVers, dbMgr->ReregisterDevice( relayID, devID, devDesc.c_str(), clientVers,
model.c_str(), osVers.c_str() ); model.c_str(), osVers.c_str(), variant.c_str() );
checkMsgs = true; checkMsgs = true;
} else { } else {
// No new information; just update the time // No new information; just update the time
checkMsgs = dbMgr->UpdateDevice( relayID, devDesc.c_str(), clientVers, checkMsgs = dbMgr->UpdateDevice( relayID, devDesc.c_str(), clientVers,
model.c_str(), osVers.c_str(), true ); model.c_str(), osVers.c_str(), variant.c_str(),
true );
if ( !checkMsgs ) { if ( !checkMsgs ) {
uint8_t buf[32]; uint8_t buf[32];
int indx = addRegID( &buf[0], relayID ); int indx = addRegID( &buf[0], relayID );
@ -1770,8 +1772,13 @@ handle_udp_packet( PacketThreadClosure* ptc )
if ( 3 >= clientVers ) { if ( 3 >= clientVers ) {
checkAllAscii( model, "bad model" ); checkAllAscii( model, "bad model" );
} }
string variant;
if ( getVLIString( &ptr, end, variant ) ) {
logf( XW_LOGINFO, "%s(): got variant %s", __func__, variant.c_str() );
}
registerDevice( relayID, &devID, ptc->addr(), registerDevice( relayID, &devID, ptc->addr(),
clientVers, devDesc, model, osVers ); clientVers, devDesc, model, osVers, variant );
} }
} }
} }

View file

@ -87,6 +87,7 @@ id INTEGER UNIQUE PRIMARY KEY
,versDesc TEXT ,versDesc TEXT
,model TEXT ,model TEXT
,osvers TEXT ,osvers TEXT
,variant TEXT
,ctime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,ctime TIMESTAMP DEFAULT CURRENT_TIMESTAMP
,mtimes TIMESTAMP[] ,mtimes TIMESTAMP[]
,unreg BOOLEAN DEFAULT FALSE ,unreg BOOLEAN DEFAULT FALSE