# p2p ```go import "github.com/Akilan1999/p2p-rendering-computation/p2p" ``` ## Index - [func AddAuthorisationKey\(PublicKey string\) error](<#AddAuthorisationKey>) - [func AddKeyToAuthorizedKeys\(path, newKey string\) error](<#AddKeyToAuthorizedKeys>) - [func CurrentPublicIP\(\) \(string, error\)](<#CurrentPublicIP>) - [func ForwardPort\(port int\) error](<#ForwardPort>) - [func GenerateHashSHA256\(text string\) \[\]byte](<#GenerateHashSHA256>) - [func GetAuthorizedKeysPath\(\) \(string, error\)](<#GetAuthorizedKeysPath>) - [func GetCurrentIPV6\(\) \(string, error\)](<#GetCurrentIPV6>) - [func Ip4or6\(s string\) string](<#Ip4or6>) - [func LocalSpeedTestIpTable\(\) error](<#LocalSpeedTestIpTable>) - [func PrettyPrint\(data interface\{\}\)](<#PrettyPrint>) - [func PrintIpTable\(\) error](<#PrintIpTable>) - [func ReadAuthorizedKeys\(path string\) \(map\[string\]bool, error\)](<#ReadAuthorizedKeys>) - [func RemoveKeyFromAuthorizedKeys\(path, keyToRemove string\) error](<#RemoveKeyFromAuthorizedKeys>) - [func UnForwardPort\(port int\) error](<#UnForwardPort>) - [func ValidateHashSHA256\(text string, Hash \[\]byte\) bool](<#ValidateHashSHA256>) - [func ViewNetworkInterface\(\) error](<#ViewNetworkInterface>) - [type IP](<#IP>) - [type IpAddress](<#IpAddress>) - [func \(s \*IpAddress\) DownloadSpeed\(\) error](<#IpAddress.DownloadSpeed>) - [func \(s \*IpAddress\) PingTest\(\) error](<#IpAddress.PingTest>) - [func \(s \*IpAddress\) UploadSpeed\(\) error](<#IpAddress.UploadSpeed>) - [type IpAddresses](<#IpAddresses>) - [func ReadIpTable\(\) \(\*IpAddresses, error\)](<#ReadIpTable>) - [func \(table \*IpAddresses\) RemoveDuplicates\(\) error](<#IpAddresses.RemoveDuplicates>) - [func \(ip \*IpAddresses\) SpeedTest\(\) error](<#IpAddresses.SpeedTest>) - [func \(ip \*IpAddresses\) SpeedTestUpdatedIPTable\(\) error](<#IpAddresses.SpeedTestUpdatedIPTable>) - [func \(i \*IpAddresses\) WriteIpTable\(\) error](<#IpAddresses.WriteIpTable>) ## func [AddAuthorisationKey]() ```go func AddAuthorisationKey(PublicKey string) error ``` AddAuthorisationKey Adds public key provided to the authorization file so that nodes can SSH into the ## func [AddKeyToAuthorizedKeys]() ```go func AddKeyToAuthorizedKeys(path, newKey string) error ``` AddKeyToAuthorizedKeys adds a new key to the authorized\_keys file if it doesn’t already exist ## func [CurrentPublicIP]() ```go func CurrentPublicIP() (string, error) ``` CurrentPublicIP Get Current Public IP address ## func [ForwardPort]() ```go func ForwardPort(port int) error ``` Port forwarding to the router ## func [GenerateHashSHA256]() ```go func GenerateHashSHA256(text string) []byte ``` ## func [GetAuthorizedKeysPath]() ```go func GetAuthorizedKeysPath() (string, error) ``` GetAuthorizedKeysPath returns the path to the authorized\_keys file ## func [GetCurrentIPV6]() ```go func GetCurrentIPV6() (string, error) ``` GetCurrentIPV6 gets the current IPV6 address based on the interface specified in the config file ## func [Ip4or6]() ```go func Ip4or6(s string) string ``` Ip4or6 Helper function to check if the IP address is IPV4 or IPV6 \(https://socketloop.com/tutorials/golang-check-if-ip-address-is-version-4-or-6\) ## func [LocalSpeedTestIpTable]() ```go func LocalSpeedTestIpTable() error ``` LocalSpeedTestIpTable Runs speed test in iptables locally only ## func [PrettyPrint]() ```go func PrettyPrint(data interface{}) ``` ## func [PrintIpTable]() ```go func PrintIpTable() error ``` PrintIpTable Print Ip table data for Cli ## func [ReadAuthorizedKeys]() ```go func ReadAuthorizedKeys(path string) (map[string]bool, error) ``` ReadAuthorizedKeys reads and returns the current contents of the authorized\_keys file as a map ## func [RemoveKeyFromAuthorizedKeys]() ```go func RemoveKeyFromAuthorizedKeys(path, keyToRemove string) error ``` ## func [UnForwardPort]() ```go func UnForwardPort(port int) error ``` UnForwardPort from router ## func [ValidateHashSHA256]() ```go func ValidateHashSHA256(text string, Hash []byte) bool ``` ValidateHashSHA256 CustomInformationKey the text and check if the text and the hash are the same, if they are then return true SHA256 is the current hashing algorthm used. ## func [ViewNetworkInterface]() ```go func ViewNetworkInterface() error ``` ViewNetworkInterface This function is created to view the network interfaces available ## type [IP]() ```go type IP struct { Query string } ``` ## type [IpAddress]() ```go type IpAddress struct { Name string `json:"Name"` MachineUsername string `json:"MachineUsername"` Ipv4 string `json:"IPV4"` Ipv6 string `json:"IPV6"` Latency time.Duration `json:"Latency"` Download float64 `json:"Download"` Upload float64 `json:"Upload"` ServerPort string `json:"ServerPort"` BareMetalSSHPort string `json:"BareMetalSSHPort"` NAT string `json:"NAT"` EscapeImplementation string `json:"EscapeImplementation"` ProxyServer string `json:"ProxyServer"` UnSafeMode bool `json:"UnSafeMode"` PublicKey string `json:"PublicKey"` CustomInformation string `json:"CustomInformation"` } ``` ### func \(\*IpAddress\) [DownloadSpeed]() ```go func (s *IpAddress) DownloadSpeed() error ``` Download Speed ### func \(\*IpAddress\) [PingTest]() ```go func (s *IpAddress) PingTest() error ``` PingTest executes test to measure latency ### func \(\*IpAddress\) [UploadSpeed]() ```go func (s *IpAddress) UploadSpeed() error ``` ## type [IpAddresses]() ```go type IpAddresses struct { IpAddress []IpAddress `json:"ip_address"` } ``` ### func [ReadIpTable]() ```go func ReadIpTable() (*IpAddresses, error) ``` ReadIpTable Read data from Ip tables from json file ### func \(\*IpAddresses\) [RemoveDuplicates]() ```go func (table *IpAddresses) RemoveDuplicates() error ``` RemoveDuplicates This is a temporary fix current functions failing to remove Duplicate IP addresses from local IP table ### func \(\*IpAddresses\) [SpeedTest]() ```go func (ip *IpAddresses) SpeedTest() error ``` SpeedTest Runs a speed test and does updates IP tables accordingly ### func \(\*IpAddresses\) [SpeedTestUpdatedIPTable]() ```go func (ip *IpAddresses) SpeedTestUpdatedIPTable() error ``` SpeedTestUpdatedIPTable Called when ip tables from httpclient/server is also passed on ### func \(\*IpAddresses\) [WriteIpTable]() ```go func (i *IpAddresses) WriteIpTable() error ``` WriteIpTable Write to IP table json file Generated by [gomarkdoc]()