Class MultiAddress
A set of steps describing how to build up a connection.
Implements
Inherited Members
Namespace: Ipfs
Assembly: Ipfs.Core.dll
Syntax
[JsonConverter(typeof(MultiAddress.Json))]
public class MultiAddress : IEquatable<MultiAddress>
Remarks
A multi address emphasizes explicitness, self-description, and portability. It allows applications to treat addresses as opaque tokens which avoids making assumptions about the address representation (e.g. length).
A multi address is represented as a series of protocol codes and values pairs. For example, an IPFS file at a sepcific address over ipv4 and tcp is "/ip4/10.1.10.10/tcp/29087/ipfs/QmVcSqVEsvm5RR9mBLjwpb2XjFVn5bPdPL69mL8PH45pPC".
A multi address is considered immutablle and value type equality is implemented.
Constructors
| Improve this Doc View SourceMultiAddress()
Creates a new instance of the MultiAddress class.
Declaration
public MultiAddress()
MultiAddress(Byte[])
Creates a new instance of the MultiAddress class from the specified byte array.
Declaration
public MultiAddress(byte[] buffer)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | buffer | ( A byte array containing the binary representation of a MultiAddress. |
Remarks
Reads the binary representation of MultiAddress from the buffer
.
The binary representation is a sequence of NetworkProtocol.
MultiAddress(Stream)
Creates a new instance of the MultiAddress class from the specified Stream.
Declaration
public MultiAddress(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | A Stream containing the binary representation of a MultiAddress. |
Remarks
Reads the binary representation of MultiAddress from the stream
.
The binary representation is a sequence of NetworkProtocol.
MultiAddress(IPAddress)
Creates a new instance of the MultiAddress class from the specified IPAddress.
Declaration
public MultiAddress(IPAddress ip)
Parameters
Type | Name | Description |
---|---|---|
IPAddress | ip |
MultiAddress(IPEndPoint)
Creates a new instance of the MultiAddress class from the specified IPEndPoint.
Declaration
public MultiAddress(IPEndPoint endpoint)
Parameters
Type | Name | Description |
---|---|---|
IPEndPoint | endpoint |
MultiAddress(String)
Creates a new instance of the MultiAddress class with the string.
Declaration
public MultiAddress(string s)
Parameters
Type | Name | Description |
---|---|---|
String | s | The string representation of a multi address, such as "/ip4/1270.0.01/tcp/5001". |
Properties
| Improve this Doc View SourceHasPeerId
Determines if the peer ID is present.
Declaration
public bool HasPeerId { get; }
Property Value
Type | Description |
---|---|
Boolean | true if the peer ID present; otherwise, false. |
Remarks
The peer ID is contained in the last protocol that
is "ipfs" or "p2p". For example, /ip4/10.1.10.10/tcp/29087/ipfs/QmVcSqVEsvm5RR9mBLjwpb2XjFVn5bPdPL69mL8PH45pPC
.
PeerId
Gets the peer ID of the multiaddress.
Declaration
public MultiHash PeerId { get; }
Property Value
Type | Description |
---|---|
MultiHash |
Remarks
The peer ID is contained in the last protocol that
is "ipfs" or "p2p". For example, /ip4/10.1.10.10/tcp/29087/ipfs/QmVcSqVEsvm5RR9mBLjwpb2XjFVn5bPdPL69mL8PH45pPC
.
Exceptions
Type | Condition |
---|---|
Exception | When the last Protocols is not "ipfs" nor "p2p". |
Protocols
The components of the MultiAddress.
Declaration
public List<NetworkProtocol> Protocols { get; }
Property Value
Type | Description |
---|---|
List<NetworkProtocol> |
Methods
| Improve this Doc View SourceClone()
Creates a deep copy of the multi address.
Declaration
public MultiAddress Clone()
Returns
Type | Description |
---|---|
MultiAddress | A new deep copy. |
Equals(MultiAddress)
Declaration
public bool Equals(MultiAddress that)
Parameters
Type | Name | Description |
---|---|---|
MultiAddress | that |
Returns
Type | Description |
---|---|
Boolean |
Equals(Object)
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj |
Returns
Type | Description |
---|---|
Boolean |
Overrides
| Improve this Doc View SourceGetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 |
Overrides
| Improve this Doc View SourceToArray()
Returns the IPFS binary representation as a byte array.
Declaration
public byte[] ToArray()
Returns
Type | Description |
---|---|
Byte[] | A byte array. |
Remarks
The binary representation is a sequence of NetworkProtocol.
ToString()
A sequence of NetworkProtocol that is readable to a human.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |
Overrides
| Improve this Doc View SourceTryCreate(Byte[])
Try to create a MultiAddress from the specified the binary encoding.
Declaration
public static MultiAddress TryCreate(byte[] bytes)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | bytes | The binary encoding of a multiaddress. |
Returns
Type | Description |
---|---|
MultiAddress | null if the bytes cannot be parsed; otherwise a MultiAddress. |
TryCreate(String)
Try to create a MultiAddress from the specified string.
Declaration
public static MultiAddress TryCreate(string s)
Parameters
Type | Name | Description |
---|---|---|
String | s | The string representation of a multi address, such as "/ip4/1270.0.01/tcp/5001". |
Returns
Type | Description |
---|---|
MultiAddress | null if the string cannot be parsed; otherwise a MultiAddress. |
WithoutPeerId()
Gets a multiaddress without the peer ID.
Declaration
public MultiAddress WithoutPeerId()
Returns
Type | Description |
---|---|
MultiAddress | Either the this multiaddress when it does not contain a peer ID; or a new MultiAddress without the peer ID. |
WithPeerId(MultiHash)
Gets a multiaddress that ends with the peer ID.
Declaration
public MultiAddress WithPeerId(MultiHash peerId)
Parameters
Type | Name | Description |
---|---|---|
MultiHash | peerId | The peer ID to end the multiaddress with. |
Returns
Type | Description |
---|---|
MultiAddress | Either the |
Exceptions
Type | Condition |
---|---|
Exception | When the mulltiaddress has the wrong peer ID. |
Write(CodedOutputStream)
Writes the binary representation to the specified Google.Protobuf.CodedOutputStream.
Declaration
public void Write(CodedOutputStream stream)
Parameters
Type | Name | Description |
---|---|---|
Google.Protobuf.CodedOutputStream | stream | The Google.Protobuf.CodedOutputStream to write to. |
Remarks
The binary representation is a sequence of NetworkProtocol.
Write(Stream)
Writes the binary representation to the specified Stream.
Declaration
public void Write(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The Stream to write to. |
Remarks
The binary representation is a sequence of NetworkProtocol.
Write(TextWriter)
Writes the string representation to the specified TextWriter.
Declaration
public void Write(TextWriter stream)
Parameters
Type | Name | Description |
---|---|---|
TextWriter | stream | The TextWriter to write to. |
Remarks
The string representation is a sequence of NetworkProtocol.
Operators
| Improve this Doc View SourceEquality(MultiAddress, MultiAddress)
Value equality.
Declaration
public static bool operator ==(MultiAddress a, MultiAddress b)
Parameters
Type | Name | Description |
---|---|---|
MultiAddress | a | |
MultiAddress | b |
Returns
Type | Description |
---|---|
Boolean |
Implicit(String to MultiAddress)
Implicit casting of a String to a MultiAddress.
Declaration
public static implicit operator MultiAddress(string s)
Parameters
Type | Name | Description |
---|---|---|
String | s | The string representation of a MultiAddress. |
Returns
Type | Description |
---|---|
MultiAddress | A new MultiAddress. |
Inequality(MultiAddress, MultiAddress)
Value inequality.
Declaration
public static bool operator !=(MultiAddress a, MultiAddress b)
Parameters
Type | Name | Description |
---|---|---|
MultiAddress | a | |
MultiAddress | b |
Returns
Type | Description |
---|---|
Boolean |