Skip to content

Commit 1a77bca

Browse files
authored
Merge pull request #343 from scalecube/add-is-secured-transport-property
Added isSecured configuration setting in TransportConfig; cleaned jav…
2 parents a796f7e + 52bf345 commit 1a77bca

File tree

7 files changed

+68
-44
lines changed

7 files changed

+68
-44
lines changed

cluster-api/src/main/java/io/scalecube/cluster/fdetector/FailureDetectorConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static FailureDetectorConfig defaultLocalConfig() {
6464
}
6565

6666
/**
67-
* Sets pingInterval.
67+
* Setter for {@code pingInterval}.
6868
*
6969
* @param pingInterval ping interval
7070
* @return new {@code FailureDetectorConfig}
@@ -80,7 +80,7 @@ public int pingInterval() {
8080
}
8181

8282
/**
83-
* Sets ping timeout.
83+
* Setter for {@code pingTimeout}.
8484
*
8585
* @param pingTimeout ping timeout
8686
* @return new {@code FailureDetectorConfig}
@@ -96,7 +96,7 @@ public int pingTimeout() {
9696
}
9797

9898
/**
99-
* Sets number of members for requesting a ping.
99+
* Setter for number of members for requesting a ping.
100100
*
101101
* @param pingReqMembers number of members for requesting a ping
102102
* @return new {@code FailureDetectorConfig}

cluster-api/src/main/java/io/scalecube/cluster/gossip/GossipConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static GossipConfig defaultLocalConfig() {
6060
}
6161

6262
/**
63-
* Sets gossipFanout.
63+
* Setter for {@code gossipFanout}.
6464
*
6565
* @param gossipFanout gossip fanout
6666
* @return new {@code GossipConfig}
@@ -76,7 +76,7 @@ public int gossipFanout() {
7676
}
7777

7878
/**
79-
* Sets gossipInterval.
79+
* Setter for {@code gossipInterval}.
8080
*
8181
* @param gossipInterval gossip interval
8282
* @return new {@code GossipConfig}
@@ -92,7 +92,7 @@ public long gossipInterval() {
9292
}
9393

9494
/**
95-
* Sets gossipRepeatMult.
95+
* Setter for {@code gossipRepeatMult}.
9696
*
9797
* @param gossipRepeatMult gossip repeat multiplier
9898
* @return new {@code GossipConfig}
@@ -108,7 +108,7 @@ public int gossipRepeatMult() {
108108
}
109109

110110
/**
111-
* Sets gossipSegmentationThreshold.
111+
* Setter for {@code gossipSegmentationThreshold}.
112112
*
113113
* @param gossipSegmentationThreshold gossip segmentation threshold
114114
* @return new {@code GossipConfig}

cluster-api/src/main/java/io/scalecube/cluster/membership/MembershipConfig.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public List<Address> seedMembers() {
7373
}
7474

7575
/**
76-
* Sets a seedMembers.
76+
* Setter for {@code seedMembers}.
7777
*
7878
* @param seedMembers seed members
7979
* @return new {@code MembershipConfig} instance
@@ -83,7 +83,7 @@ public MembershipConfig seedMembers(Address... seedMembers) {
8383
}
8484

8585
/**
86-
* Sets a seedMembers.
86+
* Setter for {@code seedMembers}.
8787
*
8888
* @param seedMembers seed members
8989
* @return new {@code MembershipConfig} instance
@@ -99,7 +99,7 @@ public int syncInterval() {
9999
}
100100

101101
/**
102-
* Sets a syncInterval.
102+
* Setter for {@code syncInterval}.
103103
*
104104
* @param syncInterval sync interval
105105
* @return new {@code MembershipConfig} instance
@@ -115,7 +115,7 @@ public int syncTimeout() {
115115
}
116116

117117
/**
118-
* Sets a syncTimeout.
118+
* Setter for {@code syncTimeout}.
119119
*
120120
* @param syncTimeout sync timeout
121121
* @return new {@code MembershipConfig} instance
@@ -131,7 +131,7 @@ public int suspicionMult() {
131131
}
132132

133133
/**
134-
* Sets a suspicionMult.
134+
* Setter for {@code suspicionMult}.
135135
*
136136
* @param suspicionMult suspicion multiplier
137137
* @return new {@code MembershipConfig} instance
@@ -147,7 +147,7 @@ public String namespace() {
147147
}
148148

149149
/**
150-
* Sets a namespace.
150+
* Setter for {@code namespace}.
151151
*
152152
* @param namespace namespace
153153
* @return new {@code MembershipConfig} instance
@@ -163,7 +163,7 @@ public int removedMembersHistorySize() {
163163
}
164164

165165
/**
166-
* Sets a removedMembersHistorySize.
166+
* Setter for {@code removedMembersHistorySize}.
167167
*
168168
* @param removedMembersHistorySize history size for remove members
169169
* @return new {@code MembershipConfig} instance

cluster-testlib/src/main/java/io/scalecube/cluster/utils/NetworkEmulator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public OutboundSettings outboundSettings(Address destination) {
6161
}
6262

6363
/**
64-
* Sets given network emulator outbound settings for specific destination.
64+
* Setter for network emulator outbound settings for specific destination.
6565
*
6666
* @param destination address of target endpoint
6767
* @param lossPercent loss in percents
@@ -74,7 +74,7 @@ public void outboundSettings(Address destination, int lossPercent, int meanDelay
7474
}
7575

7676
/**
77-
* Sets default network emulator outbound settings.
77+
* Setter for network emulator outbound settings.
7878
*
7979
* @param lossPercent loss in percents
8080
* @param meanDelay mean delay
@@ -214,7 +214,7 @@ public InboundSettings inboundSettings(Address destination) {
214214
}
215215

216216
/**
217-
* Sets given network emulator inbound settings for specific destination.
217+
* Setter for network emulator inbound settings for specific destination.
218218
*
219219
* @param shallPass shallPass inbound flag
220220
*/
@@ -225,7 +225,7 @@ public void inboundSettings(Address destination, boolean shallPass) {
225225
}
226226

227227
/**
228-
* Sets default network emulator inbound settings.
228+
* Setter for network emulator inbound settings.
229229
*
230230
* @param shallPass shallPass inbound flag
231231
*/

transport-parent/transport-api/src/main/java/io/scalecube/cluster/transport/api/TransportConfig.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public final class TransportConfig implements Cloneable {
1515
public static final int DEFAULT_LOCAL_CONNECT_TIMEOUT = 1_000;
1616

1717
private int port = 0;
18+
private boolean isSecured = false; // is client secured
1819
private int connectTimeout = DEFAULT_CONNECT_TIMEOUT;
1920
private MessageCodec messageCodec = MessageCodec.INSTANCE;
2021
private int maxFrameLength = 2 * 1024 * 1024; // 2 MB
@@ -58,7 +59,7 @@ public int port() {
5859
}
5960

6061
/**
61-
* Sets a port.
62+
* Setter for {@code port}.
6263
*
6364
* @param port port
6465
* @return new {@code TransportConfig} instance
@@ -69,12 +70,28 @@ public TransportConfig port(int port) {
6970
return t;
7071
}
7172

73+
public boolean isSecured() {
74+
return isSecured;
75+
}
76+
77+
/**
78+
* Setter to denote whether client part of the transport is secured.
79+
*
80+
* @param isSecured isSecured
81+
* @return new {@code TransportConfig} instance
82+
*/
83+
public TransportConfig secured(boolean isSecured) {
84+
TransportConfig t = clone();
85+
t.isSecured = isSecured;
86+
return t;
87+
}
88+
7289
public int connectTimeout() {
7390
return connectTimeout;
7491
}
7592

7693
/**
77-
* Sets a connectTimeout.
94+
* Setter for {@code connectTimeout}.
7895
*
7996
* @param connectTimeout connect timeout
8097
* @return new {@code TransportConfig} instance
@@ -90,7 +107,7 @@ public MessageCodec messageCodec() {
90107
}
91108

92109
/**
93-
* Sets a messageCodec.
110+
* Setter for {@code messageCodec}.
94111
*
95112
* @param messageCodec message codec
96113
* @return new {@code TransportConfig} instance
@@ -106,7 +123,7 @@ public int maxFrameLength() {
106123
}
107124

108125
/**
109-
* Sets a maxFrameLength.
126+
* Setter for {@code maxFrameLength}.
110127
*
111128
* @param maxFrameLength max frame length
112129
* @return new {@code TransportConfig} instance
@@ -122,7 +139,7 @@ public TransportFactory transportFactory() {
122139
}
123140

124141
/**
125-
* Sets a transportFactory.
142+
* Setter for {@code transportFactory}.
126143
*
127144
* @param transportFactory transport factory
128145
* @return new {@code TransportConfig} instance
@@ -146,6 +163,7 @@ public TransportConfig clone() {
146163
public String toString() {
147164
return new StringJoiner(", ", TransportConfig.class.getSimpleName() + "[", "]")
148165
.add("port=" + port)
166+
.add("isSecured=" + isSecured)
149167
.add("connectTimeout=" + connectTimeout)
150168
.add("messageCodec=" + messageCodec)
151169
.add("maxFrameLength=" + maxFrameLength)

transport-parent/transport-netty/src/main/java/io/scalecube/transport/netty/tcp/TcpSender.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,19 @@ public Mono<Void> send(Message message) {
4141
}
4242

4343
private TcpClient newTcpClient(SenderContext context, Address address) {
44-
return TcpClient.create(ConnectionProvider.newConnection())
45-
.runOn(context.loopResources())
46-
.host(address.host())
47-
.port(address.port())
48-
.option(ChannelOption.TCP_NODELAY, true)
49-
.option(ChannelOption.SO_KEEPALIVE, true)
50-
.option(ChannelOption.SO_REUSEADDR, true)
51-
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.connectTimeout())
52-
.bootstrap(
53-
b ->
54-
BootstrapHandlers.updateConfiguration(
55-
b, "outbound", new TcpChannelInitializer(config.maxFrameLength())));
44+
TcpClient tcpClient =
45+
TcpClient.create(ConnectionProvider.newConnection())
46+
.runOn(context.loopResources())
47+
.host(address.host())
48+
.port(address.port())
49+
.option(ChannelOption.TCP_NODELAY, true)
50+
.option(ChannelOption.SO_KEEPALIVE, true)
51+
.option(ChannelOption.SO_REUSEADDR, true)
52+
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.connectTimeout())
53+
.bootstrap(
54+
b ->
55+
BootstrapHandlers.updateConfiguration(
56+
b, "outbound", new TcpChannelInitializer(config.maxFrameLength())));
57+
return config.isSecured() ? tcpClient.secure() : tcpClient;
5658
}
5759
}

transport-parent/transport-netty/src/main/java/io/scalecube/transport/netty/websocket/WebsocketSender.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import reactor.netty.Connection;
1212
import reactor.netty.http.client.HttpClient;
1313
import reactor.netty.http.client.WebsocketClientSpec;
14+
import reactor.netty.tcp.TcpClient;
1415

1516
final class WebsocketSender implements Sender {
1617

@@ -47,15 +48,18 @@ public Mono<Void> send(Message message) {
4748
private HttpClient.WebsocketSender newWebsocketSender(SenderContext context, Address address) {
4849
return HttpClient.newConnection()
4950
.tcpConfiguration(
50-
tcpClient ->
51-
tcpClient
52-
.runOn(context.loopResources())
53-
.host(address.host())
54-
.port(address.port())
55-
.option(ChannelOption.TCP_NODELAY, true)
56-
.option(ChannelOption.SO_KEEPALIVE, true)
57-
.option(ChannelOption.SO_REUSEADDR, true)
58-
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.connectTimeout()))
51+
tcpClient -> {
52+
TcpClient tcpClient1 =
53+
tcpClient
54+
.runOn(context.loopResources())
55+
.host(address.host())
56+
.port(address.port())
57+
.option(ChannelOption.TCP_NODELAY, true)
58+
.option(ChannelOption.SO_KEEPALIVE, true)
59+
.option(ChannelOption.SO_REUSEADDR, true)
60+
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.connectTimeout());
61+
return config.isSecured() ? tcpClient1.secure() : tcpClient1;
62+
})
5963
.websocket(
6064
WebsocketClientSpec.builder().maxFramePayloadLength(config.maxFrameLength()).build());
6165
}

0 commit comments

Comments
 (0)