本文整理汇总了Java中org.eclipse.californium.core.network.config.NetworkConfig类的典型用法代码示例。如果您正苦于以下问题:Java NetworkConfig类的具体用法?Java NetworkConfig怎么用?Java NetworkConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetworkConfig类属于org.eclipse.californium.core.network.config包,在下文中一共展示了NetworkConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dtlsPSKRequest
import org.eclipse.californium.core.network.config.NetworkConfig; //导入依赖的package包/类
public static Response dtlsPSKRequest(String uri, String method, byte[] payload, int contentFormat, String pskIdentity, byte[] pskKey) throws Exception {
Request request = Utils.newRequest(method);
request.setURI(uri);
request.setPayload(payload);
request.getOptions().setContentFormat(contentFormat);
DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(0));
builder.setPskStore(new StaticPskStore(pskIdentity, pskKey));
builder.setSupportedCipherSuites(new CipherSuite[] {CipherSuite.TLS_PSK_WITH_AES_128_CCM_8});
DTLSConnector dtlsconnector = new DTLSConnector(builder.build(), null);
NetworkConfig nc = NetworkConfig.getStandard().setInt("COAP_SECURE_PORT", 15686);
dtlsEndpoint = new CoapEndpoint(dtlsconnector, nc);
dtlsEndpoint.start();
// execute request
request.send(dtlsEndpoint);
Response response = request.waitForResponse();
return response;
}
示例2: createX509CertClient
import org.eclipse.californium.core.network.config.NetworkConfig; //导入依赖的package包/类
public void createX509CertClient(PrivateKey privatekey, Certificate[] trustedCertificates) {
ObjectsInitializer initializer = new ObjectsInitializer();
// TODO security instance with certificate info
initializer.setInstancesForObject(LwM2mId.SECURITY, Security.noSec(
"coaps://" + server.getSecuredAddress().getHostString() + ":" + server.getSecuredAddress().getPort(),
12345));
initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U"));
List<LwM2mObjectEnabler> objects = initializer.createMandatory();
objects.add(initializer.create(2));
InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder().setAddress(clientAddress);
// TODO we should read the config from the security object
config.setIdentity(privatekey, clientX509CertChain, false);
config.setTrustStore(trustedCertificates);
CoapServer coapServer = new CoapServer();
coapServer.addEndpoint(new CoapEndpoint(new DTLSConnector(config.build()), NetworkConfig.getStandard()));
LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
builder.setObjects(objects);
client = builder.build();
}
示例3: sweep
import org.eclipse.californium.core.network.config.NetworkConfig; //导入依赖的package包/类
/**
* Iterate through all entries and remove the obsolete ones.
*/
private void sweep() {
int lifecycle = config.getInt(NetworkConfig.Keys.EXCHANGE_LIFETIME);
long oldestAllowed = System.currentTimeMillis() - lifecycle;
// Notice that the guarantees from the ConcurrentHashMap guarantee
// the correctness for this iteration.
for (Map.Entry<?,Exchange> entry:incommingMessages.entrySet()) {
Exchange exchange = entry.getValue();
if (exchange.getTimestamp() < oldestAllowed) {
//TODO check if exchange of observe relationship is periodically created and sweeped
LOGGER.finer("Mark-And-Sweep removes "+entry.getKey());
incommingMessages.remove(entry.getKey());
}
}
}
示例4: BlockwiseLayer
import org.eclipse.californium.core.network.config.NetworkConfig; //导入依赖的package包/类
/**
* Constructs a new blockwise layer.
* Changes to the configuration are observed and automatically applied.
* @param config the configuration
*/
public BlockwiseLayer(NetworkConfig config) {
this.config = config;
max_message_size = config.getInt(NetworkConfig.Keys.MAX_MESSAGE_SIZE);
preferred_block_size = config.getInt(NetworkConfig.Keys.PREFERRED_BLOCK_SIZE);
block_timeout = config.getInt(NetworkConfig.Keys.BLOCKWISE_STATUS_LIFETIME);
LOGGER.config("BlockwiseLayer uses MAX_MESSAGE_SIZE="+max_message_size+", DEFAULT_BLOCK_SIZE="+preferred_block_size+", and BLOCKWISE_STATUS_LIFETIME="+block_timeout);
observer = new NetworkConfigObserverAdapter() {
@Override
public void changed(String key, int value) {
if (NetworkConfig.Keys.MAX_MESSAGE_SIZE.equals(key))
max_message_size = value;
if (NetworkConfig.Keys.PREFERRED_BLOCK_SIZE.equals(key))
preferred_block_size = value;
if (NetworkConfig.Keys.BLOCKWISE_STATUS_LIFETIME.equals(key))
block_timeout = value;
}
};
config.addConfigObserver(observer);
}
示例5: CoapStack
import org.eclipse.californium.core.network.config.NetworkConfig; //导入依赖的package包/类
public CoapStack(NetworkConfig config, Outbox outbox) {
this.top = new StackTopAdapter();
this.outbox = outbox;
ReliabilityLayer reliabilityLayer;
if (config.getBoolean(NetworkConfig.Keys.USE_CONGESTION_CONTROL) == true) {
reliabilityLayer = CongestionControlLayer.newImplementation(config);
LOGGER.config("Enabling congestion control: " + reliabilityLayer.getClass().getSimpleName());
} else {
reliabilityLayer = new ReliabilityLayer(config);
}
this.layers =
new Layer.TopDownBuilder()
.add(top)
.add(new ObserveLayer(config))
.add(new BlockwiseLayer(config))
.add(reliabilityLayer)
.add(bottom = new StackBottomAdapter())
.create();
// make sure the endpoint sets a MessageDeliverer
}
示例6: Matcher
import org.eclipse.californium.core.network.config.NetworkConfig; //导入依赖的package包/类
public Matcher(NetworkConfig config) {
this.started = false;
this.exchangesByMID = new ConcurrentHashMap<KeyMID, Exchange>();
this.exchangesByToken = new ConcurrentHashMap<KeyToken, Exchange>();
this.ongoingExchanges = new ConcurrentHashMap<KeyUri, Exchange>();
DeduplicatorFactory factory = DeduplicatorFactory.getDeduplicatorFactory();
this.deduplicator = factory.createDeduplicator(config);
boolean randomMID = config.getBoolean(NetworkConfig.Keys.USE_RANDOM_MID_START);
if (randomMID) {
currendMID = new AtomicInteger(new Random().nextInt(1<<16));
} else {
currendMID = new AtomicInteger(0);
}
tokenSizeLimit = config.getInt(NetworkConfig.Keys.TOKEN_SIZE_LIMIT);
LOGGER.config("Matcher uses USE_RANDOM_MID_START="+randomMID+" and TOKEN_SIZE_LIMIT="+tokenSizeLimit);
healthStatusLevel = Level.parse(config.getString(NetworkConfig.Keys.HEALTH_STATUS_PRINT_LEVEL));
healthStatusInterval = config.getInt(NetworkConfig.Keys.HEALTH_STATUS_INTERVAL);
}
示例7: CoAPSAuthorizationServer
import org.eclipse.californium.core.network.config.NetworkConfig; //导入依赖的package包/类
public CoAPSAuthorizationServer() throws Exception {
add(new TokenResource());
add(new IntrospectResource());
InMemoryPskStore pskStore = new InMemoryPskStore();
pskStore.setKey(config.getPskIdentity(), config.getPskKey().getBytes());
DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(config.getCoapsPort()));
builder.setClientAuthenticationRequired(true);
builder.setPskStore(pskStore);
DTLSConnector connector = new DTLSConnector(builder.build(), null);
for (InetAddress addr : EndpointManager.getEndpointManager().getNetworkInterfaces()) {
// only binds to IPv4 addresses and localhost
if (addr instanceof Inet4Address || addr.isLoopbackAddress()) {
@SuppressWarnings("static-access")
CoapEndpoint endpoint = new CoapEndpoint(connector, new NetworkConfig().getStandard());
addEndpoint(endpoint);
EndpointManager.getEndpointManager().setDefaultSecureEndpoint(endpoint);
}
}
}
示例8: DtlsPSKServer
import org.eclipse.californium.core.network.config.NetworkConfig; //导入依赖的package包/类
public DtlsPSKServer() throws Exception {
add(new TemperatureResource());
DtlsConnectorConfig.Builder builder = new DtlsConnectorConfig.Builder(new InetSocketAddress(config.getCoapsPort()));
builder.setClientAuthenticationRequired(true);
// use the global in memory psk key store thats populated using the access tokens from the global config object
builder.setPskStore(config.getPskStorage());
DTLSConnector connector = new DTLSConnector(builder.build(), null);
for (InetAddress addr : EndpointManager.getEndpointManager().getNetworkInterfaces()) {
// only binds to IPv4 addresses and localhost
if (addr instanceof Inet4Address || addr.isLoopbackAddress()) {
@SuppressWarnings("static-access")
CoapEndpoint endpoint = new CoapEndpoint(connector, new NetworkConfig().getStandard());
addEndpoint(endpoint);
EndpointManager.getEndpointManager().setDefaultSecureEndpoint(endpoint);
}
}
}
示例9: init
import org.eclipse.californium.core.network.config.NetworkConfig; //导入依赖的package包/类
public List<Stage.ConfigIssue> init(Stage.Context context) {
List<Stage.ConfigIssue> issues = new ArrayList<>();
NetworkConfig networkConfig = NetworkConfig.createStandardWithoutFile();
networkConfig.set(NetworkConfig.Keys.DEDUPLICATOR, NetworkConfig.Keys.NO_DEDUPLICATOR);
networkConfig.set(NetworkConfig.Keys.PROTOCOL_STAGE_THREAD_COUNT, coAPServerConfigs.maxConcurrentRequests);
networkConfig.set(NetworkConfig.Keys.NETWORK_STAGE_RECEIVER_THREAD_COUNT, coAPServerConfigs.maxConcurrentRequests);
if (coAPServerConfigs.networkConfigs != null) {
for (String key: coAPServerConfigs.networkConfigs.keySet()) {
networkConfig.set(key, coAPServerConfigs.networkConfigs.get(key));
}
}
coapServer = new CoapServer(networkConfig, coAPServerConfigs.port);
coapReceiverResource = new CoapReceiverResource(context, receiver, errorQueue);
coapServer.add(coapReceiverResource);
coapServer.start();
return issues;
}
示例10: setUp
import org.eclipse.californium.core.network.config.NetworkConfig; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
int port = TestHttpClientTarget.getFreePort();
coapServer = new CoapServer(NetworkConfig.createStandardWithoutFile(), port);
coapServer.add(new CoapResource("test") {
@Override
public void handlePOST(CoapExchange exchange) {
serverRequested = true;
if (returnErrorResponse) {
exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
return;
}
requestPayload = new String(exchange.getRequestPayload());
exchange.respond(CoAP.ResponseCode.VALID);
}
});
resourceURl = "coap://localhost:" + port + "/test";
coapServer.start();
}
示例11: testCoapComponent
import org.eclipse.californium.core.network.config.NetworkConfig; //导入依赖的package包/类
@Test
public void testCoapComponent() throws Exception {
NetworkConfig.createStandardWithoutFile();
String coapConsumerUri = String.format("coap://localhost:%d/hello", AvailablePortFinder.getNextAvailable());
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
fromF(coapConsumerUri)
.convertBodyTo(String.class)
.setBody(simple("Hello ${body}"));
}
});
camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
String result = template.requestBody(coapConsumerUri + "?coapMethod=POST", "Kermit", String.class);
Assert.assertEquals("Hello Kermit", result);
} finally {
camelctx.stop();
}
}
示例12: addEndpoints
import org.eclipse.californium.core.network.config.NetworkConfig; //导入依赖的package包/类
/**
* Add individual endpoints listening on default CoAP port on all ddresses of all network interfaces.
*/
private void addEndpoints() {
int coapPort = NetworkConfig.getStandard().getInt(NetworkConfig.Keys.COAP_PORT);
for (InetAddress addr : EndpointManager.getEndpointManager().getNetworkInterfaces()) {
InetSocketAddress bindToAddress = new InetSocketAddress(addr, coapPort);
addEndpoint(new CoapEndpoint(bindToAddress));
}
}
示例13: createDeduplicator
import org.eclipse.californium.core.network.config.NetworkConfig; //导入依赖的package包/类
/**
* Creates a new deduplicator according to the specified configuration.
* @param config the configuration
* @return the deduplicator
*/
public Deduplicator createDeduplicator(NetworkConfig config) {
String type = config.getString(NetworkConfig.Keys.DEDUPLICATOR);
if (NetworkConfig.Keys.DEDUPLICATOR_MARK_AND_SWEEP.equals(type)) return new SweepDeduplicator(config);
else if (NetworkConfig.Keys.DEDUPLICATOR_CROP_ROTATION.equals(type)) return new CropRotation(config);
else if (NetworkConfig.Keys.NO_DEDUPLICATOR.equals(type)) return new NoDeduplicator();
else {
LOGGER.warning("Unknown deduplicator type: " + type);
return new NoDeduplicator();
}
}
示例14: CropRotation
import org.eclipse.californium.core.network.config.NetworkConfig; //导入依赖的package包/类
public CropRotation(NetworkConfig config) {
this.rotation = new Rotation();
maps = new ExchangeMap[3];
maps[0] = new ExchangeMap();
maps[1] = new ExchangeMap();
maps[2] = new ExchangeMap();
first = 0;
second = 1;
period = config.getInt(NetworkConfig.Keys.CROP_ROTATION_PERIOD);
}
示例15: ReliabilityLayer
import org.eclipse.californium.core.network.config.NetworkConfig; //导入依赖的package包/类
/**
* Constructs a new reliability layer.
* Changes to the configuration are observed and automatically applied.
* @param config the configuration
*/
public ReliabilityLayer(NetworkConfig config) {
this.config = config;
ack_timeout = config.getInt(NetworkConfig.Keys.ACK_TIMEOUT);
ack_random_factor = config.getFloat(NetworkConfig.Keys.ACK_RANDOM_FACTOR);
ack_timeout_scale = config.getFloat(NetworkConfig.Keys.ACK_TIMEOUT_SCALE);
max_retransmit = config.getInt(NetworkConfig.Keys.MAX_RETRANSMIT);
LOGGER.config("ReliabilityLayer uses ACK_TIMEOUT="+ack_timeout+", ACK_RANDOM_FACTOR="+ack_random_factor+", and ACK_TIMEOUT_SCALE="+ack_timeout_scale);
observer = new NetworkConfigObserverAdapter() {
@Override
public void changed(String key, int value) {
if (NetworkConfig.Keys.ACK_TIMEOUT.equals(key))
ack_timeout = value;
if (NetworkConfig.Keys.MAX_RETRANSMIT.equals(key))
max_retransmit = value;
}
@Override
public void changed(String key, float value) {
if (NetworkConfig.Keys.ACK_RANDOM_FACTOR.equals(key))
ack_random_factor = value;
if (NetworkConfig.Keys.ACK_TIMEOUT_SCALE.equals(key))
ack_timeout_scale = value;
}
};
config.addConfigObserver(observer);
}