Commit 6e01e832596e1769bdd53cb634b3019833e93bf4
1 parent
89a803bf
Exists in
master
1.注册server时不发送请求 2.请求增加seckey
Showing
6 changed files
with
28 additions
and
7 deletions
Show diff stats
build.gradle
@@ -55,7 +55,7 @@ uploadArchives { | @@ -55,7 +55,7 @@ uploadArchives { | ||
55 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) | 55 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) |
56 | } | 56 | } |
57 | pom.project { | 57 | pom.project { |
58 | - version '1.1.9' | 58 | + version '1.1.11' |
59 | artifactId ARTIFACT_Id | 59 | artifactId ARTIFACT_Id |
60 | groupId GROUP_ID | 60 | groupId GROUP_ID |
61 | packaging TYPE | 61 | packaging TYPE |
src/main/java/com/taover/heartbeat/ClientHolderImpl.java
@@ -9,6 +9,8 @@ import org.apache.commons.lang3.StringUtils; | @@ -9,6 +9,8 @@ import org.apache.commons.lang3.StringUtils; | ||
9 | 9 | ||
10 | import com.taover.heartbeat.bean.ClientInstance; | 10 | import com.taover.heartbeat.bean.ClientInstance; |
11 | import com.taover.heartbeat.bean.ClientRequest; | 11 | import com.taover.heartbeat.bean.ClientRequest; |
12 | +import com.taover.heartbeat.bean.Instance; | ||
13 | +import com.taover.util.UtilEncrypt; | ||
12 | 14 | ||
13 | public class ClientHolderImpl implements ClientHolder{ | 15 | public class ClientHolderImpl implements ClientHolder{ |
14 | Map<String, ClientInstance> clientMap = new HashMap<String, ClientInstance>(); | 16 | Map<String, ClientInstance> clientMap = new HashMap<String, ClientInstance>(); |
@@ -42,9 +44,12 @@ public class ClientHolderImpl implements ClientHolder{ | @@ -42,9 +44,12 @@ public class ClientHolderImpl implements ClientHolder{ | ||
42 | } | 44 | } |
43 | 45 | ||
44 | private boolean validClientRequest(ClientRequest clientRequest) { | 46 | private boolean validClientRequest(ClientRequest clientRequest) { |
47 | + long time = clientRequest.getUnixtime(); | ||
48 | + String seckey = UtilEncrypt.MD5Lower32(clientRequest.getCode()+clientRequest.getFixRateSec()+clientRequest.getMaxWaitSec()+time+Instance.SERVER_ENCRPT_SURFFIX); | ||
45 | if(StringUtils.isNotBlank(clientRequest.getCode()) | 49 | if(StringUtils.isNotBlank(clientRequest.getCode()) |
46 | && StringUtils.isNotBlank(clientRequest.getIp()) | 50 | && StringUtils.isNotBlank(clientRequest.getIp()) |
47 | - && clientRequest.getFixRateSec() > 0) { | 51 | + && clientRequest.getFixRateSec() > 0 |
52 | + && seckey.equals(clientRequest.getSeckey())) { | ||
48 | return true; | 53 | return true; |
49 | }else { | 54 | }else { |
50 | return false; | 55 | return false; |
src/main/java/com/taover/heartbeat/ServerHolderImpl.java
@@ -25,7 +25,7 @@ public class ServerHolderImpl implements ServerHolder { | @@ -25,7 +25,7 @@ public class ServerHolderImpl implements ServerHolder { | ||
25 | serverMap.put(server.getIdentity(), server); | 25 | serverMap.put(server.getIdentity(), server); |
26 | } | 26 | } |
27 | } | 27 | } |
28 | - server.flush(); | 28 | + //server.flush(); |
29 | } | 29 | } |
30 | 30 | ||
31 | @Override | 31 | @Override |
src/main/java/com/taover/heartbeat/bean/ClientRequest.java
@@ -8,6 +8,7 @@ public class ClientRequest { | @@ -8,6 +8,7 @@ public class ClientRequest { | ||
8 | private int maxWaitSec = Instance.DEFAULT_MAX_WAIT_SEC; | 8 | private int maxWaitSec = Instance.DEFAULT_MAX_WAIT_SEC; |
9 | private int fixRateSec = Instance.DEFAULT_FIX_RATE_SEC; | 9 | private int fixRateSec = Instance.DEFAULT_FIX_RATE_SEC; |
10 | private long unixtime; | 10 | private long unixtime; |
11 | + private String seckey = ""; | ||
11 | 12 | ||
12 | public String getCode() { | 13 | public String getCode() { |
13 | return code; | 14 | return code; |
@@ -39,13 +40,20 @@ public class ClientRequest { | @@ -39,13 +40,20 @@ public class ClientRequest { | ||
39 | public void setUnixtime(long unixtime) { | 40 | public void setUnixtime(long unixtime) { |
40 | this.unixtime = unixtime; | 41 | this.unixtime = unixtime; |
41 | } | 42 | } |
43 | + public String getSeckey() { | ||
44 | + return seckey; | ||
45 | + } | ||
46 | + public void setSeckey(String seckey) { | ||
47 | + this.seckey = seckey; | ||
48 | + } | ||
42 | 49 | ||
43 | - public ClientRequest(String code, String ip, int maxWaitSec, int fixRateSec, long unixtime) { | 50 | + public ClientRequest(String code, String ip, int maxWaitSec, int fixRateSec, long unixtime, String seckey) { |
44 | this.code = code; | 51 | this.code = code; |
45 | this.ip = ip; | 52 | this.ip = ip; |
46 | this.maxWaitSec = maxWaitSec; | 53 | this.maxWaitSec = maxWaitSec; |
47 | this.fixRateSec = fixRateSec; | 54 | this.fixRateSec = fixRateSec; |
48 | this.unixtime = unixtime; | 55 | this.unixtime = unixtime; |
56 | + this.seckey = seckey; | ||
49 | } | 57 | } |
50 | 58 | ||
51 | public ClientRequest(ClientRequest clientRequest) { | 59 | public ClientRequest(ClientRequest clientRequest) { |
@@ -54,6 +62,7 @@ public class ClientRequest { | @@ -54,6 +62,7 @@ public class ClientRequest { | ||
54 | this.maxWaitSec = clientRequest.getMaxWaitSec(); | 62 | this.maxWaitSec = clientRequest.getMaxWaitSec(); |
55 | this.fixRateSec = clientRequest.getFixRateSec(); | 63 | this.fixRateSec = clientRequest.getFixRateSec(); |
56 | this.unixtime = clientRequest.getUnixtime(); | 64 | this.unixtime = clientRequest.getUnixtime(); |
65 | + this.seckey = clientRequest.getSeckey(); | ||
57 | } | 66 | } |
58 | 67 | ||
59 | public static ClientRequest createClientRequest(HttpServletRequest request) { | 68 | public static ClientRequest createClientRequest(HttpServletRequest request) { |
@@ -61,11 +70,13 @@ public class ClientRequest { | @@ -61,11 +70,13 @@ public class ClientRequest { | ||
61 | String maxWaitSec = request.getParameter("maxWaitSec"); | 70 | String maxWaitSec = request.getParameter("maxWaitSec"); |
62 | String fixRateSec = request.getParameter("fixRateSec"); | 71 | String fixRateSec = request.getParameter("fixRateSec"); |
63 | String unixtime = request.getParameter("unixtime"); | 72 | String unixtime = request.getParameter("unixtime"); |
73 | + String seckey = request.getParameter("seckey"); | ||
64 | String ip = request.getRemoteHost(); | 74 | String ip = request.getRemoteHost(); |
65 | return new ClientRequest(code, ip, | 75 | return new ClientRequest(code, ip, |
66 | maxWaitSec==null?Instance.DEFAULT_MAX_WAIT_SEC:Integer.valueOf(maxWaitSec), | 76 | maxWaitSec==null?Instance.DEFAULT_MAX_WAIT_SEC:Integer.valueOf(maxWaitSec), |
67 | fixRateSec==null?Instance.DEFAULT_FIX_RATE_SEC:Integer.valueOf(fixRateSec), | 77 | fixRateSec==null?Instance.DEFAULT_FIX_RATE_SEC:Integer.valueOf(fixRateSec), |
68 | - unixtime==null?System.currentTimeMillis()/1000:Long.valueOf(unixtime)); | 78 | + unixtime==null?System.currentTimeMillis()/1000:Long.valueOf(unixtime), |
79 | + seckey); | ||
69 | } | 80 | } |
70 | 81 | ||
71 | public String getIdentity() { | 82 | public String getIdentity() { |
src/main/java/com/taover/heartbeat/bean/Instance.java
1 | package com.taover.heartbeat.bean; | 1 | package com.taover.heartbeat.bean; |
2 | 2 | ||
3 | public interface Instance { | 3 | public interface Instance { |
4 | + public static final String SERVER_ENCRPT_SURFFIX = "taover"; | ||
5 | + | ||
4 | public static final int DEFAULT_MAX_WAIT_SEC = -1; | 6 | public static final int DEFAULT_MAX_WAIT_SEC = -1; |
5 | public static final int DEFAULT_FIX_RATE_SEC = -1; | 7 | public static final int DEFAULT_FIX_RATE_SEC = -1; |
6 | 8 |
src/main/java/com/taover/heartbeat/bean/ServerInstance.java
@@ -2,6 +2,7 @@ package com.taover.heartbeat.bean; | @@ -2,6 +2,7 @@ package com.taover.heartbeat.bean; | ||
2 | 2 | ||
3 | import java.net.SocketTimeoutException; | 3 | import java.net.SocketTimeoutException; |
4 | 4 | ||
5 | +import com.taover.util.UtilEncrypt; | ||
5 | import com.taover.util.UtilHttpByOkHttp; | 6 | import com.taover.util.UtilHttpByOkHttp; |
6 | 7 | ||
7 | public class ServerInstance implements Instance { | 8 | public class ServerInstance implements Instance { |
@@ -53,8 +54,10 @@ public class ServerInstance implements Instance { | @@ -53,8 +54,10 @@ public class ServerInstance implements Instance { | ||
53 | } | 54 | } |
54 | } | 55 | } |
55 | 56 | ||
56 | - private String getUrlParams() { | ||
57 | - return "?code="+this.code+"&fixRateSec="+this.fixRateSec+"&maxWaitSec="+this.maxWaitSec+"&unixtime="+(System.currentTimeMillis()/1000); | 57 | + private String getUrlParams() { |
58 | + long time = (System.currentTimeMillis()/1000L); | ||
59 | + String seckey = UtilEncrypt.MD5Lower32(this.code+this.fixRateSec+this.maxWaitSec+time+SERVER_ENCRPT_SURFFIX); | ||
60 | + return "?code="+this.code+"&fixRateSec="+this.fixRateSec+"&maxWaitSec="+this.maxWaitSec+"&unixtime="+time+"&seckey="+seckey; | ||
58 | } | 61 | } |
59 | 62 | ||
60 | private boolean isLatestRequestGreateEqualFixRateSec() { | 63 | private boolean isLatestRequestGreateEqualFixRateSec() { |