input
is in correct IPv6 notation.
+ */
+ public static boolean isIPv6StdAddress(final String input) {
+ return IPV6_STD_PATTERN.matcher(input).matches();
+ }
+
+ /**
+ * Check if the given address is a valid IPv6 address in the hex-compressed notation
+ * The format is 'xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx'. If all digits in a block are '0'
+ * the block can be left empty.
+ *
+ * @param input ip-address to check
+ * @return true if input
is in correct IPv6 (hex-compressed) notation.
+ */
+ public static boolean isIPv6HexCompressedAddress(final String input) {
+ return IPV6_HEX_COMPRESSED_PATTERN.matcher(input).matches();
+ }
+
+ /**
+ * Check if the given address is a valid IPv6 address in the mixed-standard or mixed-compressed notation.
+ * IPV6 Mixed mode consists of two parts, the first 96 bits (up to 6 blocks of 4 hex digits) are IPv6
+ * the IPV6 part can be either compressed or uncompressed
+ * the second block is a full IPv4 address
+ * e.g. '0:0:0:0:0:0:172.12.55.18'
+ *
+ * @param input ip-address to check
+ * @return true if input
is in correct IPv6 (mixed-standard or mixed-compressed) notation.
+ */
+ public static boolean isIPv6MixedAddress(final String input) {
+ int splitIndex = input.lastIndexOf(':');
+ if (splitIndex == -1) {
+ return false;
+ }
+ //the last part is a ipv4 address
+ boolean ipv4PartValid = isIPv4Address(input.substring(splitIndex + 1));
+ String ipV6Part = input.substring(ZERO, splitIndex + 1);
+ if (DOUBLE_COLON.equals(ipV6Part)) {
+ return ipv4PartValid;
+ }
+ boolean ipV6UncompressedDetected = IPV6_MIXED_UNCOMPRESSED_REGEX.matcher(ipV6Part).matches();
+ boolean ipV6CompressedDetected = IPV6_MIXED_COMPRESSED_REGEX.matcher(ipV6Part).matches();
+ return ipv4PartValid && (ipV6UncompressedDetected || ipV6CompressedDetected);
+ }
+
+ /**
+ * Check if input
is an IPv4 address mapped into a IPv6 address. These are
+ * starting with "::ffff:" followed by the IPv4 address in a dot-seperated notation.
+ * The format is '::ffff:d.d.d.d'
+ *
+ * @param input ip-address to check
+ * @return true if input
is in correct IPv6 notation containing an IPv4 address
+ */
+ public static boolean isIPv6IPv4MappedAddress(final String input) {
+ if (input.length() > SEVEN && input.substring(ZERO, SEVEN).equalsIgnoreCase(DOUBLE_COLON_FFFF)) {
+ String lowerPart = input.substring(SEVEN);
+ return isIPv4Address(lowerPart);
+ }
+ return false;
+ }
+
+ /**
+ * Check if input
is a link local IPv6 address starting with "fe80:" and containing
+ * a zone index with "%xxx". The zone index will not be checked.
+ *
+ * @param input ip-address to check
+ * @return true if address part of input
is in correct IPv6 notation.
+ */
+ public static boolean isLinkLocalIPv6WithZoneIndex(String input) {
+ if (input.length() > FIVE && input.substring(ZERO, FIVE).equalsIgnoreCase(FE80)) {
+ int lastIndex = input.lastIndexOf(PERCENT);
+ if (lastIndex > ZERO && lastIndex < (input.length() - 1)) {
+ String ipPart = input.substring(ZERO, lastIndex);
+ return isIPv6StdAddress(ipPart) || isIPv6HexCompressedAddress(ipPart);
+ }
+ }
+ return false;
+ }
+}
diff --git a/common/src/main/java/io/seata/common/util/NetUtil.java b/common/src/main/java/io/seata/common/util/NetUtil.java
index a5decf5c970..4feb47d1b7c 100644
--- a/common/src/main/java/io/seata/common/util/NetUtil.java
+++ b/common/src/main/java/io/seata/common/util/NetUtil.java
@@ -15,17 +15,22 @@
*/
package io.seata.common.util;
+import io.seata.common.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Enumeration;
-import java.util.regex.Pattern;
+import java.util.LinkedHashSet;
+import java.util.Set;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* The type Net util.
@@ -34,13 +39,25 @@
*/
public class NetUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(NetUtil.class);
- private static final String LOCALHOST = "127.0.0.1";
+ public static final boolean PREFER_IPV6_ADDRESSES = Boolean.parseBoolean(
+ System.getProperty("java.net.preferIPv6Addresses"));
+
+ private static final String LOCALHOST = "127.0.0.1";
private static final String ANY_HOST = "0.0.0.0";
+ public static final String LOCALHOST_IPV6 = "0:0:0:0:0:0:0:1";
+ public static final String LOCALHOST_SHORT_IPV6 = "::1";
+ public static final String ANY_HOST_IPV6 = "0:0:0:0:0:0:0:0";
+ public static final String ANY_HOST_SHORT_IPV6 = "::";
+
private static volatile InetAddress LOCAL_ADDRESS = null;
- private static final Pattern IP_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3,5}$");
+ private static final Sete.length)throw new RangeError("Index out of range")}function w(e,t,n,r){t<0&&(t=65535+t+1);for(var a=0,o=Math.min(e.length-n,2);a e.length)throw new RangeError("Index out of range")}function w(e,t,n,r){t<0&&(t=65535+t+1);for(var a=0,o=Math.min(e.length-n,2);a d&&(f-=2*Math.PI),!s&&d>f&&(d-=2*Math.PI)}var I=d-f;if(Math.abs(I)>m){var P=d,A=c,E=u;d=f+m*(s&&d>f?1:-1),y=t(c=p+r*Math.cos(d),u=g+i*Math.sin(d),r,i,o,0,s,A,E,[d,P,p,g])}I=d-f;var k=Math.cos(f),O=Math.sin(f),T=Math.cos(d),N=Math.sin(d),L=Math.tan(I/4),j=4/3*r*L,D=4/3*i*L,B=[e,n],R=[e+j*O,n-D*k],G=[c+j*N,u-D*T],F=[c,u];if(R[0]=2*B[0]-R[0],R[1]=2*B[1]-R[1],l)return[R,G,F].concat(y);for(var Y=[],X=0,z=(y=[R,G,F].concat(y).join().split(",")).length;X=e.length){if(a)return-1;n=e.length-1}else if(n<0){if(!a)return-1;n=0}if("string"==typeof t&&(t=d.from(t,r)),d.isBuffer(t))return 0===t.length?-1:m(e,t,n,r,a);if("number"==typeof t)return t&=255,d.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?(a?Uint8Array.prototype.indexOf:Uint8Array.prototype.lastIndexOf).call(e,t,n):m(e,[t],n,r,a);throw new TypeError("val must be string, number or Buffer")}function m(e,t,n,r,a){var o=1,i=e.length,s=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;i/=o=2,s/=2,n/=2}function l(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(a)for(var u=-1,c=n;c>8,r=r%256,a.push(r),a.push(n);return a}(t,e.length-n),e,n,r)}function L(e,t,n){n=Math.min(e.length,n);for(var r=[],a=t;athis.length)throw new RangeError("Attempt to write outside buffer bounds");r=r||"utf8";for(var o,i,s,l=!1;;)switch(r){case"hex":var u=this,c=e,d=t,p=n,f=(d=Number(d)||0,u.length-d);if((!p||f<(p=Number(p)))&&(p=f),(f=c.length)%2!=0)throw new TypeError("Invalid hex string");f/2>1,c=-7,d=n?a-1:0,p=n?-1:1,a=e[t+d];for(d+=p,o=a&(1<<-c)-1,a>>=-c,c+=s;0t?a[t+1]:a[0])}),n[r]||(o=a[0]),i.onSort(r,o)},i.keydownHandler=function(e){e.preventDefault(),e.stopPropagation(),e.keyCode===T.ENTER&&i.handleClick()},i.onSort=function(e,t){var n={};n[e]=t,i.props.onSort(e,t,n)},e=e,y()(i,e)}Of.displayName="Sort";Nf=K.a.Component,g()(jf,Nf),jf.prototype.componentWillUnmount=function(){this.destory()},jf.prototype.destory=function(){x.off(document,"mousemove",this.onMouseMove),x.off(document,"mouseup",this.onMouseUp),this.select()},jf.prototype.unSelect=function(){k.setStyle(document.body,{userSelect:"none",cursor:"ew-resize"}),document.body.setAttribute("unselectable","on")},jf.prototype.select=function(){k.setStyle(document.body,{userSelect:"",cursor:""}),document.body.removeAttribute("unselectable")},jf.prototype.render=function(){var e=this.props.prefix;return K.a.createElement("a",{className:e+"table-resize-handler",onMouseDown:this.onMouseDown})},b=c=jf,c.propTypes={prefix:p.a.string,rtl:p.a.bool,onChange:p.a.func,dataIndex:p.a.string,tableEl:p.a.any,resizeProxyDomRef:p.a.any,cellDomRef:p.a.any,col:p.a.any,hasLock:p.a.bool,asyncResizable:p.a.bool},c.defaultProps={onChange:function(){}};var Nf,a=b;function jf(){h()(this,jf);var a=y()(this,Nf.call(this));return a.showResizeProxy=function(){a.props.resizeProxyDomRef.style.cssText="display:block;left:"+a.startLeft+"px;"},a.moveResizeProxy=function(){var e=a.startLeft+a.changedPageX;a.props.resizeProxyDomRef.style.cssText="left:"+e+"px;display:block;"},a.resetResizeProxy=function(){a.asyncResizeFlag&&a.props.onChange(a.props.dataIndex,a.changedPageX),a.changedPageX=0,a.tRight=0,a.asyncResizeFlag=!1,a.props.resizeProxyDomRef.style.cssText="display:none;"},a.movingLimit=function(){var e=a.startLeft+a.changedPageX;e>a.tRight&&(e=a.tRight,a.changedPageX=a.tRight-a.startLeft),e-a.cellLeft0&&(i=1/Math.sqrt(i),t[0]=e[0]*i,t[1]=e[1]*i),t},e.dot=function(t,e){return t[0]*e[0]+t[1]*e[1]},e.cross=function(t,e,n){var r=e[0]*n[1]-e[1]*n[0];return t[0]=t[1]=0,t[2]=r,t},e.lerp=function(t,e,n,r){var i=e[0],o=e[1];return t[0]=i+r*(n[0]-i),t[1]=o+r*(n[1]-o),t},e.random=function(t,e){e=e||1;var n=2*r.RANDOM()*Math.PI;return t[0]=Math.cos(n)*e,t[1]=Math.sin(n)*e,t},e.transformMat2=function(t,e,n){var r=e[0],i=e[1];return t[0]=n[0]*r+n[2]*i,t[1]=n[1]*r+n[3]*i,t},e.transformMat2d=function(t,e,n){var r=e[0],i=e[1];return t[0]=n[0]*r+n[2]*i+n[4],t[1]=n[1]*r+n[3]*i+n[5],t},e.transformMat3=function(t,e,n){var r=e[0],i=e[1];return t[0]=n[0]*r+n[3]*i+n[6],t[1]=n[1]*r+n[4]*i+n[7],t},e.transformMat4=function(t,e,n){var r=e[0],i=e[1];return t[0]=n[0]*r+n[4]*i+n[12],t[1]=n[1]*r+n[5]*i+n[13],t},e.rotate=function(t,e,n,r){var i=e[0]-n[0],o=e[1]-n[1],a=Math.sin(r),s=Math.cos(r);return t[0]=i*s-o*a+n[0],t[1]=i*a+o*s+n[1],t},e.angle=function(t,e){var n=t[0],r=t[1],i=e[0],o=e[1],a=n*n+r*r;a>0&&(a=1/Math.sqrt(a));var s=i*i+o*o;s>0&&(s=1/Math.sqrt(s));var c=(n*i+r*o)*a*s;return c>1?0:c<-1?Math.PI:Math.acos(c)},e.str=function(t){return"vec2("+t[0]+", "+t[1]+")"},e.exactEquals=function(t,e){return t[0]===e[0]&&t[1]===e[1]},e.equals=function(t,e){var n=t[0],i=t[1],o=e[0],a=e[1];return Math.abs(n-o)<=r.EPSILON*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(i-a)<=r.EPSILON*Math.max(1,Math.abs(i),Math.abs(a))};var r=function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}(n(59));function i(){var t=new r.ARRAY_TYPE(2);return r.ARRAY_TYPE!=Float32Array&&(t[0]=0,t[1]=0),t}function o(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t}function a(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t}function s(t,e,n){return t[0]=e[0]/n[0],t[1]=e[1]/n[1],t}function c(t,e){var n=e[0]-t[0],r=e[1]-t[1];return Math.sqrt(n*n+r*r)}function u(t,e){var n=e[0]-t[0],r=e[1]-t[1];return n*n+r*r}function l(t){var e=t[0],n=t[1];return Math.sqrt(e*e+n*n)}function h(t){var e=t[0],n=t[1];return e*e+n*n}e.len=l,e.sub=o,e.mul=a,e.div=s,e.dist=c,e.sqrDist=u,e.sqrLen=h,e.forEach=function(){var t=i();return function(e,n,r,i,o,a){var s,c=void 0;for(n||(n=2),r||(r=0),s=i?Math.min(i*n+r,e.length):e.length,c=r;c0?1:-1};var o=function(t){for(var e=1;e