“Net:NAT穿透”与“Vertx: Future异步操作设计”:页面之间的差异

来自WHY42
(页面间差异)
无编辑摘要
 
 
第1行: 第1行:
NAT穿越(NAT traversal)涉及TCP/IP网络中的一个常见问题,即在处于使用了NAT设备的私有TCP/IP网络中的主机之间建立连接的问题。
=Future相关操作的设计=
== AsyncResult ==
AsyncResult表示一个异步操作的结果,这个结果要么是成功的,要么是失败的。
<syntaxhighlight lang="java">
interface AsyncResult<T> {
    /* 获取异步结果,或者失败原因。倘若失败,那么结果为null */
    T getResult();
    Throwable cause();
    boolean succeeded();
    boolean failed();


常用的NAT穿透的技术有:
    /* 对结果进行转换。如果成功,那么可以将成功的结果转换为另一种形式;否则可以得到一个替代的结果。*/
    <V> AsyncResult<V> map(Function<T, V> mapper);
    <V> AsyncResult<V> map(V value);
    <V> AsyncResult<V> mapEmpty();
    AsyncResult<T> otherwise(T value);
    AsyncResult<T> otherwise(Function<Throwable, T> mapper);
    AsyncResult<T> otherwiseEmpty();
}
</syntaxhighlight>


;Socket Secure:(SOCKS) is a technology created in the early 1990s that uses proxy servers to relay traffic between networks or systems
==Future==
;Traversal Using Relays around NAT (TURN): is a relay protocol designed specifically for NAT traversal.
Future表示一个尚未完成的异步操作,并继承自AsyncResult
;NAT hole punching: is a general technique that exploits how NATs handle some protocols (for example, UDP, TCP, or ICMP) to allow previously blocked packets through the NAT.
<syntaxhighlight lang="java">
;Session Traversal Utilities for NAT (STUN): is a standardized set of methods and a network protocol for NAT hole punching. It was designed for UDP but was also extended to TCP.
interface Future<T>
;Interactive Connectivity Establishment (ICE): is a complete protocol for using STUN and/or TURN to do NAT traversal while picking the best network route available. It fills in some of the missing pieces and deficiencies that were not mentioned by STUN specification.
    extends AsyncResult<T> {
;UPnP Internet Gateway Device Protocol (IGDP): is supported by many small NAT gateways in home or small office settings. It allows a device on a network to ask the router to open a port.
    boolean isComplete();
;NAT-PMP: is a protocol introduced by Apple as an alternative to IGDP.
    Future<T> onComplete(Handler<AsyncResult<T>> handler);
;PCP: is a successor of NAT-PMP.
    Future<T> onSuccess(Handler<T> handler);
;Application-level gateway (ALG): is a component of a firewall or NAT that allows for configuring NAT traversal filters.[2] It is claimed by numerous people that this technique creates more problems than it solves
    Future<T> onFailure(Handler<Throwable> handler);
    <V> Future<V> compose(Function<T, Future<V>> mapper);
    <V> Future<V> compose(Function<T, Future<V>> successMapper,  
                      Function<Throwable, Future<V>> failureMapper);
    Future<T> recover(Function<Throwable, Future<T>> mapper);
    <V> Future<V> transform(Function<AsyncResult<T>, Future<V>> mapper);
    <V> Future<T> eventually(Function<Void, Future<V>> mapper);
    CompletionStage<T> toCompletionState();
}


[[Category:Distributed]]
</syntaxhighlight>
[[Category:Network]]
 
[[Category:Vert.x]]

2021年7月25日 (日) 08:21的版本

Future相关操作的设计

AsyncResult

AsyncResult表示一个异步操作的结果,这个结果要么是成功的,要么是失败的。

interface AsyncResult<T> {
    /* 获取异步结果,或者失败原因。倘若失败,那么结果为null */
    T getResult();
    Throwable cause();
    boolean succeeded();
    boolean failed();

    /* 对结果进行转换。如果成功,那么可以将成功的结果转换为另一种形式;否则可以得到一个替代的结果。*/
    <V> AsyncResult<V> map(Function<T, V> mapper);
    <V> AsyncResult<V> map(V value);
    <V> AsyncResult<V> mapEmpty();
    AsyncResult<T> otherwise(T value);
    AsyncResult<T> otherwise(Function<Throwable, T> mapper);
    AsyncResult<T> otherwiseEmpty();
}

Future

Future表示一个尚未完成的异步操作,并继承自AsyncResult

interface Future<T>
    extends AsyncResult<T> {
    boolean isComplete();
    Future<T> onComplete(Handler<AsyncResult<T>> handler);
    Future<T> onSuccess(Handler<T> handler);
    Future<T> onFailure(Handler<Throwable> handler);
    <V> Future<V> compose(Function<T, Future<V>> mapper);
    <V> Future<V> compose(Function<T, Future<V>> successMapper, 
                      Function<Throwable, Future<V>> failureMapper);
    Future<T> recover(Function<Throwable, Future<T>> mapper);
    <V> Future<V> transform(Function<AsyncResult<T>, Future<V>> mapper);
    <V> Future<T> eventually(Function<Void, Future<V>> mapper);
    CompletionStage<T> toCompletionState();
}