Skip to content

Commit

Permalink
Fixes #158 Detect backend master/slave role in DNS TXT Record
Browse files Browse the repository at this point in the history
Really a hack because info.getPropertyNames() always return null
when there is no equal sign in the record. Tested on 0.27 with
one host running code prior to the MythTV commit and a 2nd host
with the commit running either as a master or a slave.
  • Loading branch information
billmeek committed Sep 2, 2013
1 parent 6c6190c commit 4153e37
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.IOException;
import java.net.InetAddress;
import java.util.Enumeration;
import java.util.EventListener;
import java.util.List;

Expand Down Expand Up @@ -507,8 +508,12 @@ public void onPause() {
*/
@SuppressWarnings( "deprecation" )
public void serviceAdded( ServiceEvent event ) {

Log.v( TAG, "serviceAdded : enter" );

byte[] txtRecord;
boolean isMasterRole = false;

if( null != mProgressDialog ) {
mProgressDialog.dismiss();
mProgressDialog = null;
Expand All @@ -517,11 +522,26 @@ public void serviceAdded( ServiceEvent event ) {
Log.v( TAG, "serviceAdded : " + event.getDNS().getServiceInfo( event.getType(), event.getName() ).toString() );

ServiceInfo info = event.getDNS().getServiceInfo( event.getType(), event.getName() );

// 0.26 and 0.25 have an empty TXT Record. 0.27+ have a 6 followed by "master" or 5/"slave".
// Crude hack because Enumeration<String> txtRecords = info.getPropertyNames(); doesn't
// seem to handle the case of records with (legal) entries with no =. E.g. role=master vs.
// just master.

txtRecord = info.getTextBytes();

Log.v( TAG, "serviceAdded : backend role = " + txtRecord[0] + " ( 0 or 6 = master, 5 = slave)");

if( txtRecord[0] == 0 || txtRecord[0] == 6 )
{
isMasterRole = true;
}

final String hostname = info.getInet4Address().getHostAddress();
final int port = info.getPort();
Log.v( TAG, "serviceAdded : masterbackend=" + ( "http://" + hostname + ":" + port + "/" ) );

if( null != hostname && !hostname.isEmpty() ) {
if( null != hostname && !hostname.isEmpty() && isMasterRole ) {

LocationProfile profile = new LocationProfile();
profile.setId( -1 );
Expand Down

0 comments on commit 4153e37

Please sign in to comment.