Peer Connection
Acquire Endpoint
When confirming the Endpoint configured when you use the SDK, you can first read the section on VPC Service Domain Name in the Developer Guide to understand the Endpoint concept. Baidu AI Cloud currently opens the multi-region (Region) support. Please refer to the part of network product VPC in Region Selection Introduction. The peer connection services are a part of VPC services, and use the VPC service domain name.
Get the Key
To use Baidu Cloud products, you need to have a Baidu Cloud account and a valid AK (Access Key ID ) and SK (Secret Access Key) for signature verification. You can obtain and understand your AK/SK information through the following steps:
1.[Register Baidu Cloud Account](https://login.bce.baidu.com/reg.html? tpl=bceplat&from=portal)
2.[Create AK/SK](https://console.bce.baidu.com/iam/? _=1513940574695#/iam/accesslist)
PeerConnClient
The PeerConnClient encapsulates the API of peer connection services, and simplifies the interaction between developers and peer connection services. The users can call the methods in PeerConnClient to configure the peer connection.
New PeerConnClient
When creating PeerConnClient, you need to first use Endpoint, AK and SK to configure the g_PeerConnConfigs, and then use the g_PeerConnConfigs to configure the PeerConnClient. The specific configuration method is as follows:
$g_PeerConnConfigs = array(
'credentials' => array(
'ak' => '',
'sk' => '',
),
'endpoint' => '',
);
public $client;
client = new PeerConnClient($g_PeerConnConfigs);
Create a Peer Connection
When the peer connection is created, attention should be paid to:
- For the peer connection of the same account, the system will trigger the opposite terminal for automatic acceptance.
- For the cross-account peer connection, the peer connection is available only after being accepted by the acceptor.
- For the peer connections with the same local region and opposite terminal region, the billing parameter only supports the postpaid (the billing parameter should be transmitted, but the bill is 0).
- Only one peer connection exists between any two VPCs.
- The VPCs of the initiator and the acceptor cannot be the same.
- If the local vpc and opposite terminal vpc are both relay vpcs, the peer connection cannot be established.
The createPeerConn function can be used to create the peer connection in the specified VPC, and is defined as below:
public function createPeerConn($bandwidthInMbps, $localVpcId, $peerVpcId, $peerRegion, $billing, $peerAccountId = null, $peerIfName = null, $description = null, $localIfName = null, $clientToken = null, $options = array())
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
bandwidthInMbps | int | Yes | the maximum bandwidth of peer connection, in mbps. |
localVpcId | string | Yes | Local VPC ID |
peerVpcId | string | Yes | Opposite terminal VPC ID |
peerRegion | string | Yes | Opposite terminal region |
description | string | No | Description |
localIfName | string | No | Local interface name |
peerAccountId | string | No | Opposite terminal account ID |
peerIfName | string | No | Opposite terminal interface name |
billing | Customized Billing type | Yes | The billing mode supports the purchase by postpayment and monthly repayment. Refer to Billing Description for details. |
clientToken | string | No | The idempotence Token is a ASCII string with a length not exceeding 64 bits. Refer to Idempotence Token for details. |
options | array | No | For the additional configurations, the parameters in the option can be used to temporarily replace the default parameters (AK, SK and Endpoint) in NatClient. |
For the customized Billing type definition, refer to Billing.php. The region parameter is as follows:
Name | Value |
---|---|
Beijing | bj |
Guangzhou | gz |
Suzhou | su |
Shanghai | fsh |
Hong Kong | hkg |
Baoding | bd |
Du Xiaoman Finance Special Zone | hb-fsg |
Wuhan | fwh |
Singapore | sin |
Du Xiaoman Finance Special Zone II | bjfsg |
Query the Peer Connection List
The listPeerConns function can be used to query the peer connection list, and is defined as below:
public function listPeerConns($vpcId, $marker = null, $maxKeys = 1000, $options = array())
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
vpcId | string | Yes | ID of peer connection VPC |
marker | string | No | Starting location of query for batch acquisition of lists |
maxKeys | int | No | Maximum number contained in each page, generally not exceeding 1000. The default value is 1000. |
options | array | No | For the additional configurations, the parameters in the option can be used to temporarily replace the default parameters (AK, SK and Endpoint) in NatClient. |
Query the Peer Connection Details
The getPeerConn function can be used to query the peer connection details, and is defined as below:
public function getPeerConn($peerConnId, $options = array())
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
peerConnId | string | Yes | peer connection ID |
options | array | No | For the additional configurations, the parameters in the option can be used to temporarily replace the default parameters (AK, SK and Endpoint) in NatClient. |
Update the Local Interface Name and Comments of peer Connection
The updatePeerConn function can be used to update the peer connection, and is defined as below:
public function updatePeerConn($peerConnId, $localIfId, $localIfName = null, $description = null, $clientToken = null, $options = array())
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
peerConnId | string | Yes | peer connection ID |
localIfId | string | Yes | Local interface ID |
description | string | No | Description |
localIfName | string | No | Local interface name |
clientToken | string | No | The idempotence Token is a ASCII string with a length not exceeding 64 bits. Refer to Idempotence Token for details. |
options | array | No | For the additional configurations, the parameters in the option can be used to temporarily replace the default parameters (AK, SK and Endpoint) in NatClient. |
Process the Peer Connection Application
- When the connection request timeout initiated by the initiator is 7 days, the status of the peer connection of the initiator after time-out is "Consultation Failed".
- After the acceptor denies, the status of the peer connection of the initiator is "Consultation Failed".
The acceptPeerConnApply function can be used to accept the peer connection, and is defined as below:
public function acceptPeerConnApply($peerConnId, $clientToken = null, $options = array())
The rejectPeerConnApply function can be used to reject the peer connection, and is defined as below:
public function rejectPeerConnApply($peerConnId, $clientToken = null, $options = array())
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
peerConnId | string | Yes | peer connection ID |
clientToken | string | No | The idempotence Token is a ASCII string with a length not exceeding 64 bits. Refer to Idempotence Token for details. |
options | array | No | For the additional configurations, the parameters in the option can be used to temporarily replace the default parameters (AK, SK and Endpoint) in NatClient. |
Release the Peer Connection
The releasePeerConn function can be used to release the peer connection, and is defined as below:
public function releasePeerConn($peerConnId, $clientToken = null, $options = array())
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
peerConnId | string | Yes | peer connection ID |
clientToken | string | No | The idempotence Token is a ASCII string with a length not exceeding 64 bits. Refer to Idempotence Token for details. |
options | array | No | For the additional configurations, the parameters in the option can be used to temporarily replace the default parameters (AK, SK and Endpoint) in NatClient. |
Upgrade and Degrade of peer Connection Bandwidth
The resizePeerConn function can be used to release the peer connection, and is defined as below:
public function resizePeerConn($peerConnId, $newBandwidthInMbps, $clientToken = null, $options = array())
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
peerConnId | string | Yes | peer connection ID |
newBandwidthInMbps | int | Yes | the maximum bandwidth of peer connection, in mbps. |
clientToken | string | No | The idempotence Token is a ASCII string with a length not exceeding 64 bits. Refer to Idempotence Token for details. |
options | array | No | For the additional configurations, the parameters in the option can be used to temporarily replace the default parameters (AK, SK and Endpoint) in NatClient. |
Peer Connection Renewal
- The postpaid peer connection cannot be renewed.
- The cross-account renewal can only be operated by the initiator.
The purchaseReservedPeerConn function can be used to release the peer connection, and is defined as below:
public function purchaseReservedPeerConn($peerConnId, $billing, $clientToken = null, $options = array())
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
peerConnId | string | Yes | peer connection ID |
billing | Customized Billing type | Yes | For the billion mode, refer to Billing Description for details. |
clientToken | string | No | The idempotence Token is a ASCII string with a length not exceeding 64 bits. Refer to Idempotence Token for details. |
options | array | No | For the additional configurations, the parameters in the option can be used to temporarily replace the default parameters (AK, SK and Endpoint) in NatClient. |
Open the Synchronous DNS of peer Connection
- The DNS can be enabled only when the status of peer connection is "Available".
- The synchronization of DNS cannot be enabled when the DNS status of peer connection is "Synchronizing" or "Synchronization Closed".
The openPeerConnSyncDns function can be used to release the peer connection, and is defined as below:
public function openPeerConnSyncDns($peerConnId, $role, $clientToken = null, $options = array())
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
peerConnId | string | Yes | peer connection ID |
role | string | Yes | "initiator" and "acceptor" |
clientToken | string | No | The idempotence Token is a ASCII string with a length not exceeding 64 bits. Refer to Idempotence Token for details. |
options | array | No | For the additional configurations, the parameters in the option can be used to temporarily replace the default parameters (AK, SK and Endpoint) in NatClient. |
Close the Synchronous DNS of peer Connection
- The DNS can be closed only when the status of peer connection is "available".
- The synchronization of DNS cannot be closed when the DNS status of peer connection is "Synchronizing" or "Synchronization Closed".
The closePeerConnSyncDns function can be used to release the peer connection, and is defined as below:
public function closePeerConnSyncDns($peerConnId, $role, $clientToken = null, $options = array())
The parameters are described as follows:
Parameter name | Type | Required or not | Description |
---|---|---|---|
peerConnId | string | Yes | peer connection ID |
role | string | Yes | "initiator" and "acceptor" |
clientToken | string | No | The idempotence Token is a ASCII string with a length not exceeding 64 bits. Refer to Idempotence Token for details. |
options | array | No | For the additional configurations, the parameters in the option can be used to temporarily replace the default parameters (AK, SK and Endpoint) in NatClient. |