diff --git a/Connection.cpp b/Connection.cpp index f7532d0..efbca7d 100644 --- a/Connection.cpp +++ b/Connection.cpp @@ -10,7 +10,6 @@ #include "Connection.h" #include "Log.h" - #ifndef NDEBUG #define CONNECTION_DEBUG #endif @@ -39,6 +38,9 @@ bool Connection::init() // through exception runtime if fails receiver_ = new UdpListeningReceiveSocket( IpEndpointName( IpEndpointName::ANY_ADDRESS, connections_[0].port_handshake ), &listener_ ); + // validate hostname + connections_[0].name = APP_NAME "@" + NetworkToolkit::hostname() + + "." + std::to_string(connections_[0].port_handshake-HANDSHAKE_PORT); // all good trial = MAX_HANDSHAKE; } @@ -87,11 +89,26 @@ ConnectionInfo Connection::info(int index) } -void Connection::print() +struct hasName: public std::unary_function { - for(int i = 0; i::const_iterator p = std::find_if(connections_.begin(), connections_.end(), hasName(name)); + if (p != connections_.end()) + id = std::distance(connections_.begin(), p); + + return id; } int Connection::index(ConnectionInfo i) const @@ -105,6 +122,13 @@ int Connection::index(ConnectionInfo i) const return id; } +void Connection::print() +{ + for(int i = 0; iAsString() ); info.port_handshake = (arg++)->AsInt32(); info.port_stream_send = (arg++)->AsInt32(); info.port_stream_receive = (arg++)->AsInt32(); diff --git a/Connection.h b/Connection.h index a2abbcb..26b9faf 100644 --- a/Connection.h +++ b/Connection.h @@ -18,34 +18,37 @@ protected: struct ConnectionInfo { - std::string address_; + std::string address; int port_handshake; int port_stream_send; int port_stream_receive; + std::string name; int alive; ConnectionInfo () { - address_ = "localhost"; + address = "127.0.0.1"; port_handshake = HANDSHAKE_PORT; port_stream_send = STREAM_REQUEST_PORT; port_stream_receive = STREAM_RESPONSE_PORT; + name = "user@localhost"; alive = ALIVE; } inline ConnectionInfo& operator = (const ConnectionInfo& o) { if (this != &o) { - this->address_ = o.address_; + this->address = o.address; this->port_handshake = o.port_handshake; this->port_stream_send = o.port_stream_send; this->port_stream_receive = o.port_stream_receive; + this->name = o.name; } return *this; } inline bool operator == (const ConnectionInfo& o) const { - return this->address_.compare(o.address_) == 0 + return this->address.compare(o.address) == 0 && this->port_handshake == o.port_handshake; } @@ -73,6 +76,7 @@ public: int numHosts () const; int index(ConnectionInfo i) const; + int index(const std::string &name) const; ConnectionInfo info(int index = 0); // index 0 for self private: diff --git a/NetworkToolkit.cpp b/NetworkToolkit.cpp index 8377ef8..cc0b6a5 100644 --- a/NetworkToolkit.cpp +++ b/NetworkToolkit.cpp @@ -156,3 +156,12 @@ std::string NetworkToolkit::closest_host_ip(const std::string &ip) return address; } + +std::string NetworkToolkit::hostname() +{ + char hostname[1024]; + hostname[1023] = '\0'; + gethostname(hostname, 1023); + + return std::string(hostname); +} diff --git a/NetworkToolkit.h b/NetworkToolkit.h index 00850fb..f48036f 100644 --- a/NetworkToolkit.h +++ b/NetworkToolkit.h @@ -38,6 +38,8 @@ std::vector host_ips(); bool is_host_ip(const std::string &ip); std::string closest_host_ip(const std::string &ip); +std::string hostname(); + } #endif // NETWORKTOOLKIT_H diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index edbf68f..4d942c6 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -39,6 +39,7 @@ using namespace std; #include "Log.h" #include "SystemToolkit.h" #include "RenderingManager.h" +#include "Connection.h" #include "ActionManager.h" #include "Resource.h" #include "FileDialog.h" @@ -2311,21 +2312,12 @@ void Navigator::RenderNewPannel() new_source_preview_.setSource( Mixer::manager().createSourceDevice(namedev), namedev); } } - -// for (uint n = 0; n < NetworkToolkit::DEFAULT; ++n){ -// if (ImGui::Selectable( NetworkToolkit::protocol_name[n] )) { -// new_source_preview_.setSource( Mixer::manager().createSourceNetwork("192.168.0.30") ); -// } -// } - - for (int d = 0; d < NetworkHosts::manager().numHosts(); ++d){ - std::string namehost = NetworkHosts::manager().name(d); + for (int d = 1; d < Connection::manager().numHosts(); ++d){ + std::string namehost = Connection::manager().info(d).name; if (ImGui::Selectable( namehost.c_str() )) { - new_source_preview_.setSource( Mixer::manager().createSourceNetwork(namehost), namehost); } } - ImGui::EndCombo(); }