99
1010import io .grpc .Server ;
1111import io .grpc .netty .shaded .io .grpc .netty .NettyServerBuilder ;
12+ import io .grpc .netty .shaded .io .netty .handler .ssl .ApplicationProtocolConfig ;
13+ import io .grpc .netty .shaded .io .netty .handler .ssl .ApplicationProtocolNames ;
1214import io .grpc .netty .shaded .io .netty .handler .ssl .SslContextBuilder ;
1315import org .apache .commons .logging .Log ;
1416import org .apache .commons .logging .LogFactory ;
2325 */
2426public final class NettyGrpcServer implements GrpcServer {
2527
26- private static Log logger = LogFactory .getLog (NettyGrpcServer .class );
28+ private static final Log LOGGER = LogFactory .getLog (NettyGrpcServer .class );
2729
2830 private final Server server ;
31+
2932 /**
3033 * init netty grpc server.
3134 *
32- * @param chaincodeBase - chaincode implementation (invoke, init)
35+ * @param chaincodeBase - chaincode implementation (invoke, init)
3336 * @param chaincodeServerProperties - setting for grpc server
3437 * @throws IOException
3538 */
@@ -56,27 +59,37 @@ public NettyGrpcServer(final ChaincodeBase chaincodeBase, final ChaincodeServerP
5659 final File keyCertChainFile = Paths .get (chaincodeServerProperties .getKeyCertChainFile ()).toFile ();
5760 final File keyFile = Paths .get (chaincodeServerProperties .getKeyFile ()).toFile ();
5861
62+ SslContextBuilder sslContextBuilder ;
5963 if (chaincodeServerProperties .getKeyPassword () == null || chaincodeServerProperties .getKeyPassword ().isEmpty ()) {
60- serverBuilder . sslContext ( SslContextBuilder .forServer (keyCertChainFile , keyFile ). build () );
64+ sslContextBuilder = SslContextBuilder .forServer (keyCertChainFile , keyFile );
6165 } else {
62- serverBuilder . sslContext ( SslContextBuilder .forServer (keyCertChainFile , keyFile , chaincodeServerProperties .getKeyPassword ()). build ());
66+ sslContextBuilder = SslContextBuilder .forServer (keyCertChainFile , keyFile , chaincodeServerProperties .getKeyPassword ());
6367 }
68+
69+ ApplicationProtocolConfig apn = new ApplicationProtocolConfig (
70+ ApplicationProtocolConfig .Protocol .ALPN ,
71+ ApplicationProtocolConfig .SelectorFailureBehavior .NO_ADVERTISE ,
72+ ApplicationProtocolConfig .SelectedListenerFailureBehavior .ACCEPT ,
73+ ApplicationProtocolNames .HTTP_2 );
74+ sslContextBuilder .applicationProtocolConfig (apn );
75+
76+ serverBuilder .sslContext (sslContextBuilder .build ());
6477 }
6578
66- logger .info ("<<<<<<<<<<<<<chaincodeServerProperties>>>>>>>>>>>>:\n " );
67- logger .info ("PortChaincodeServer:" + chaincodeServerProperties .getPortChaincodeServer ());
68- logger .info ("MaxInboundMetadataSize:" + chaincodeServerProperties .getMaxInboundMetadataSize ());
69- logger .info ("MaxInboundMessageSize:" + chaincodeServerProperties .getMaxInboundMessageSize ());
70- logger .info ("MaxConnectionAgeSeconds:" + chaincodeServerProperties .getMaxConnectionAgeSeconds ());
71- logger .info ("KeepAliveTimeoutSeconds:" + chaincodeServerProperties .getKeepAliveTimeoutSeconds ());
72- logger .info ("PermitKeepAliveTimeMinutes:" + chaincodeServerProperties .getPermitKeepAliveTimeMinutes ());
73- logger .info ("KeepAliveTimeMinutes:" + chaincodeServerProperties .getKeepAliveTimeMinutes ());
74- logger .info ("PermitKeepAliveWithoutCalls:" + chaincodeServerProperties .getPermitKeepAliveWithoutCalls ());
75- logger .info ("KeyPassword:" + chaincodeServerProperties .getKeyPassword ());
76- logger .info ("KeyCertChainFile:" + chaincodeServerProperties .getKeyCertChainFile ());
77- logger .info ("KeyFile:" + chaincodeServerProperties .getKeyFile ());
78- logger .info ("isTlsEnabled:" + chaincodeServerProperties .isTlsEnabled ());
79- logger .info ("\n " );
79+ LOGGER .info ("<<<<<<<<<<<<<chaincodeServerProperties>>>>>>>>>>>>:\n " );
80+ LOGGER .info ("PortChaincodeServer:" + chaincodeServerProperties .getPortChaincodeServer ());
81+ LOGGER .info ("MaxInboundMetadataSize:" + chaincodeServerProperties .getMaxInboundMetadataSize ());
82+ LOGGER .info ("MaxInboundMessageSize:" + chaincodeServerProperties .getMaxInboundMessageSize ());
83+ LOGGER .info ("MaxConnectionAgeSeconds:" + chaincodeServerProperties .getMaxConnectionAgeSeconds ());
84+ LOGGER .info ("KeepAliveTimeoutSeconds:" + chaincodeServerProperties .getKeepAliveTimeoutSeconds ());
85+ LOGGER .info ("PermitKeepAliveTimeMinutes:" + chaincodeServerProperties .getPermitKeepAliveTimeMinutes ());
86+ LOGGER .info ("KeepAliveTimeMinutes:" + chaincodeServerProperties .getKeepAliveTimeMinutes ());
87+ LOGGER .info ("PermitKeepAliveWithoutCalls:" + chaincodeServerProperties .getPermitKeepAliveWithoutCalls ());
88+ LOGGER .info ("KeyPassword:" + chaincodeServerProperties .getKeyPassword ());
89+ LOGGER .info ("KeyCertChainFile:" + chaincodeServerProperties .getKeyCertChainFile ());
90+ LOGGER .info ("KeyFile:" + chaincodeServerProperties .getKeyFile ());
91+ LOGGER .info ("isTlsEnabled:" + chaincodeServerProperties .isTlsEnabled ());
92+ LOGGER .info ("\n " );
8093
8194 this .server = serverBuilder .build ();
8295 }
@@ -87,7 +100,7 @@ public NettyGrpcServer(final ChaincodeBase chaincodeBase, final ChaincodeServerP
87100 * @throws IOException
88101 */
89102 public void start () throws IOException {
90- logger .info ("start grpc server" );
103+ LOGGER .info ("start grpc server" );
91104 Runtime .getRuntime ()
92105 .addShutdownHook (
93106 new Thread (() -> {
@@ -105,15 +118,15 @@ public void start() throws IOException {
105118 * @throws InterruptedException
106119 */
107120 public void blockUntilShutdown () throws InterruptedException {
108- logger .info ("Waits for the server to become terminated." );
121+ LOGGER .info ("Waits for the server to become terminated." );
109122 server .awaitTermination ();
110123 }
111124
112125 /**
113126 * shutdown now grpc server.
114127 */
115128 public void stop () {
116- logger .info ("shutdown now grpc server." );
129+ LOGGER .info ("shutdown now grpc server." );
117130 server .shutdownNow ();
118131 }
119132}
0 commit comments