c-multiaddr/README.md

35 lines
1.7 KiB
Markdown
Raw Permalink Normal View History

2016-10-26 08:48:01 +00:00
# c-multiaddr
multiaddr for IPFS in C.
2016-11-10 08:15:13 +00:00
### Multiaddr provides easy networking protocols nesting, easy encapsulation of extra protocols, easy tunneling, etc.
# Usage:
2016-11-10 08:19:07 +00:00
#### All you need to include is multiaddr.h
2016-11-10 08:15:13 +00:00
## Maddr struct:
2017-02-21 19:02:42 +00:00
* char * string; // String that contains addresses such as /ip4/192.168.1.1/
2017-02-21 19:04:06 +00:00
* uint8_t * bytes; // uint8_t * that contains the enecoded address
* size_t bsize; //size_t that contains the real bytes size (Use it whenever using the bytes so you don't input trash!)
2016-11-10 11:07:23 +00:00
2017-02-21 19:02:42 +00:00
## New Multi Address From String(multiaddress_new_from_string)
struct MultiAddress* a = multiaddress_new_from_string("/ip4/127.0.0.1/tcp/8080/");
2016-11-10 08:15:13 +00:00
## Obtaining the byte buffer(.bytes, .bsize[0]):
2017-02-21 19:02:42 +00:00
printf("TEST BYTES: %s\n",Var_To_Hex(a->bsize, a->bytes));
2016-11-10 08:15:13 +00:00
Var_To_Hex = Byte Buffer to Hex String
2016-11-10 08:27:58 +00:00
Hex_To_Var = Hex String to Byte Buffer
2016-11-10 08:15:13 +00:00
## Encapsulation & Decapsulation(m_encapsulate, m_decapsulate)
2016-11-10 08:24:23 +00:00
#### Remember, Decapsulation happens from right to left, never in reverse, if you have /ip4/udp/ipfs/ if you decapsulate "udp" you will also take out ipfs!
* Now the string is: /ip4/192.168.1.1/
2017-02-21 19:04:06 +00:00
* multiaddress_encapsulate(a,"/udp/3333/"); //Adds udp/3333/
2016-11-10 08:24:23 +00:00
* Now the string is: /ip4/192.168.1.1/udp/3333/
2017-02-21 19:02:42 +00:00
* multiaddress_decapsulate(a,"udp"); //Removes udp protocol and its address
2016-11-10 08:24:23 +00:00
* Now the string is: /ip4/192.168.1.1/
2017-02-21 19:02:42 +00:00
* multiaddress_encapsulate(a,"/tcp/8080");
2016-11-10 08:26:10 +00:00
* Now the string is: /ip4/192.168.1.1/tcp/8080/
2016-11-10 08:15:13 +00:00
# Constructing a multiaddress from bytes:
2016-11-10 08:26:10 +00:00
2017-02-21 19:02:42 +00:00
* struct MultiAddress* beta;
* beta = multiaddress_new_from_bytes(a->bytes,a->bsize); //This will already construct back to the string too!
* printf("B STRING: %s\n",beta->string); //So after encapsulation and decapsulation atm this string would
2016-11-10 08:26:10 +00:00
* contain: /ip4/192.168.1.1/tcp/8080/
2016-11-10 08:15:13 +00:00