From 272204223e0d24647a0d7bf217887c98f84a179d Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 1 Feb 2019 17:01:32 -0800 Subject: [PATCH] make md5sum calculation available everywhere I want to log sums to see when they arrive on relay. And also add some missing @Overrides I noticed. --- .../eehouse/android/xw4/CommsTransport.java | 6 +++- .../org/eehouse/android/xw4/MultiMsgSink.java | 6 +++- .../java/org/eehouse/android/xw4/Utils.java | 28 ++++++++++++++++++- .../eehouse/android/xw4/jni/JNIUtilsImpl.java | 27 +++--------------- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/CommsTransport.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/CommsTransport.java index b486b89fa..b91129832 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/CommsTransport.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/CommsTransport.java @@ -347,9 +347,10 @@ public class CommsTransport implements TransportProcs, } // TransportProcs interface - + @Override public int getFlags() { return COMMS_XPORT_FLAGS_NONE; } + @Override public int transportSend( byte[] buf, String msgNo, CommsAddrRec addr, CommsConnType conType, int gameID ) { @@ -386,17 +387,20 @@ public class CommsTransport implements TransportProcs, return nSent; } + @Override public void relayConnd( String room, int devOrder, boolean allHere, int nMissing ) { m_tpHandler.tpmRelayConnd( room, devOrder, allHere, nMissing ); } + @Override public void relayErrorProc( XWRELAY_ERROR relayErr ) { m_tpHandler.tpmRelayErrorProc( relayErr ); } + @Override public boolean relayNoConnProc( byte[] buf, String msgNo, String relayID ) { Assert.fail(); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiMsgSink.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiMsgSink.java index 955bb6039..b067a12a7 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiMsgSink.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiMsgSink.java @@ -84,9 +84,10 @@ public class MultiMsgSink implements TransportProcs { } /***** TransportProcs interface *****/ - + @Override public int getFlags() { return COMMS_XPORT_FLAGS_HASNOCONN; } + @Override public int transportSend( byte[] buf, String msgNo, CommsAddrRec addr, CommsConnType typ, int gameID ) { @@ -118,15 +119,18 @@ public class MultiMsgSink implements TransportProcs { return nSent; } + @Override public void relayErrorProc( XWRELAY_ERROR relayErr ) { } + @Override public void relayConnd( String room, int devOrder, boolean allHere, int nMissing ) { } + @Override public boolean relayNoConnProc( byte[] buf, String msgNo, String relayID ) { // Assert.fail(); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java index 72c354dee..8aece99bb 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Utils.java @@ -68,13 +68,13 @@ import java.io.InputStreamReader; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.security.MessageDigest; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Random; - import org.eehouse.android.xw4.Perms23.Perm; import org.eehouse.android.xw4.jni.CommonPrefs; import org.eehouse.android.xw4.loc.LocUtils; @@ -359,6 +359,32 @@ public class Utils { return str; } + public static String getMD5SumFor( byte[] bytes ) + { + String result = null; + if ( bytes != null ) { + byte[] digest = null; + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] buf = new byte[128]; + int nLeft = bytes.length; + int offset = 0; + while ( 0 < nLeft ) { + int len = Math.min( buf.length, nLeft ); + System.arraycopy( bytes, offset, buf, 0, len ); + md.update( buf, 0, len ); + nLeft -= len; + offset += len; + } + digest = md.digest(); + } catch ( java.security.NoSuchAlgorithmException nsae ) { + Log.ex( TAG, nsae ); + } + result = Utils.digestToString( digest ); + } + return result; + } + public static void setChecked( View parent, int id, boolean value ) { CheckBox cbx = (CheckBox)parent.findViewById( id ); diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIUtilsImpl.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIUtilsImpl.java index 5d8c6a060..86ceb0e83 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIUtilsImpl.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/jni/JNIUtilsImpl.java @@ -30,7 +30,6 @@ import org.eehouse.android.xw4.Utils; import java.io.ByteArrayInputStream; import java.io.InputStreamReader; -import java.security.MessageDigest; import java.util.ArrayList; public class JNIUtilsImpl implements JNIUtils { @@ -62,6 +61,7 @@ public class JNIUtilsImpl implements JNIUtils { * [ faces = new ArrayList(); @@ -130,32 +130,13 @@ public class JNIUtilsImpl implements JNIUtils { faces.add( face.toArray( new String[face.size()] ) ); } + @Override public String getMD5SumFor( byte[] bytes ) { - String result = null; - if ( bytes != null ) { - byte[] digest = null; - try { - MessageDigest md = MessageDigest.getInstance("MD5"); - byte[] buf = new byte[128]; - int nLeft = bytes.length; - int offset = 0; - while ( 0 < nLeft ) { - int len = Math.min( buf.length, nLeft ); - System.arraycopy( bytes, offset, buf, 0, len ); - md.update( buf, 0, len ); - nLeft -= len; - offset += len; - } - digest = md.digest(); - } catch ( java.security.NoSuchAlgorithmException nsae ) { - Log.ex( TAG, nsae ); - } - result = Utils.digestToString( digest ); - } - return result; + return Utils.getMD5SumFor( bytes ); } + @Override public String getMD5SumFor( String dictName, byte[] bytes ) { String result = null;