1
1
package org .fisco .bcos .fisco ;
2
2
3
+ import org .fisco .bcos .channel .protocol .ChannelPrococolExceiption ;
4
+
3
5
public enum EnumNodeVersion {
4
6
BCOS_2_0_0_RC1 ("2.0.0-rc1" ),
5
7
BCOS_2_0_0_RC2 ("2.0.0-rc2" ),
@@ -22,11 +24,91 @@ public void setVersion(String version) {
22
24
this .version = version ;
23
25
}
24
26
25
- public static boolean channelProtocolHandleShakeSupport (String version ) {
26
- return !(version .equals (BCOS_2_0_0_RC1 .getVersion ())
27
- || version .equals (BCOS_2_0_0_RC2 .getVersion ())
28
- || version .equals (BCOS_2_0_0_RC3 .getVersion ())
29
- || version .equals (BCOS_2_0_0 .getVersion ())
30
- || version .equals (BCOS_2_0_1 .getVersion ()));
27
+ // the object of node version
28
+ class Version {
29
+ private int major ;
30
+ private int minor ;
31
+ private int patch ;
32
+ private String ext ;
33
+
34
+ @ Override
35
+ public String toString () {
36
+ return "Version [major="
37
+ + major
38
+ + ", minor="
39
+ + minor
40
+ + ", patch="
41
+ + patch
42
+ + ", ext="
43
+ + ext
44
+ + "]" ;
45
+ }
46
+
47
+ public int getMajor () {
48
+ return major ;
49
+ }
50
+
51
+ public void setMajor (int major ) {
52
+ this .major = major ;
53
+ }
54
+
55
+ public int getMinor () {
56
+ return minor ;
57
+ }
58
+
59
+ public void setMinor (int minor ) {
60
+ this .minor = minor ;
61
+ }
62
+
63
+ public int getPatch () {
64
+ return patch ;
65
+ }
66
+
67
+ public void setPatch (int patch ) {
68
+ this .patch = patch ;
69
+ }
70
+
71
+ public String getExt () {
72
+ return ext ;
73
+ }
74
+
75
+ public void setExt (String ext ) {
76
+ this .ext = ext ;
77
+ }
78
+ }
79
+
80
+ private static Version getClassVersion (String version ) throws ChannelPrococolExceiption {
81
+ try {
82
+ // node version str format : "a.b.c" or "a.b.c-rcx"
83
+ String [] s0 = version .trim ().split ("-" );
84
+
85
+ Version v = EnumNodeVersion .BCOS_2_0_0 .new Version ();
86
+ if (s0 .length > 1 ) {
87
+ v .setExt (s0 [1 ]);
88
+ }
89
+
90
+ //
91
+ String [] s1 = s0 [0 ].split ("\\ ." );
92
+ if (s1 .length >= 3 ) {
93
+ v .setMajor (Integer .parseInt (s1 [0 ].trim ()));
94
+ v .setMinor (Integer .parseInt (s1 [1 ].trim ()));
95
+ v .setPatch (Integer .parseInt (s1 [2 ].trim ()));
96
+ } else { // invaid format
97
+ throw new ChannelPrococolExceiption (
98
+ " invalid node version format, version: " + version );
99
+ }
100
+
101
+ return v ;
102
+ } catch (Exception e ) {
103
+ throw new ChannelPrococolExceiption (
104
+ " invalid node version format, version: " + version );
105
+ }
106
+ }
107
+
108
+ public static boolean channelProtocolHandleShakeSupport (String version )
109
+ throws ChannelPrococolExceiption {
110
+ Version v = getClassVersion (version );
111
+ // 2.1.0 and above
112
+ return (v .getMajor () == 2 ) && (v .getMinor () >= 1 );
31
113
}
32
114
}
0 commit comments