Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::ResolveSession Class Reference

#include <src/slic3r/Utils/Bonjour.hpp>

+ Inheritance diagram for Slic3r::ResolveSession:
+ Collaboration diagram for Slic3r::ResolveSession:

Public Member Functions

 ResolveSession (const ResolveSocket *sckt, Bonjour::ReplyFn rfn)
 
void handle_receive (const boost::system::error_code &error, size_t bytes) override
 

Public Attributes

std::vector< char > buffer
 
boost::asio::ip::udp::endpoint remote_endpoint
 

Protected Attributes

const ResolveSocketsocket
 
Bonjour::ReplyFn replyfn
 

Detailed Description

Constructor & Destructor Documentation

◆ ResolveSession()

Slic3r::ResolveSession::ResolveSession ( const ResolveSocket sckt,
Bonjour::ReplyFn  rfn 
)
inline
139: UdpSession(rfn), socket(sckt) {}
const ResolveSocket * socket
Definition Bonjour.hpp:143
UdpSession(Bonjour::ReplyFn rfn)
Definition Bonjour.cpp:618

Member Function Documentation

◆ handle_receive()

void Slic3r::ResolveSession::handle_receive ( const boost::system::error_code &  error,
size_t  bytes 
)
overridevirtual

Implements Slic3r::UdpSession.

775{
776 assert(socket);
777 if (error) {
778 // todo: what level? do we even log? There might be callbacks when timer runs out
779 BOOST_LOG_TRIVIAL(info) << error.message();
780 return;
781 }
782 if (bytes == 0 || !replyfn) {
783 // todo: log something?
784 return;
785 }
786
787 buffer.resize(bytes);
788#if 0
789 std::string str;
790 char const hex_chars[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
791 for (size_t i = 0; i < buffer.size(); i++) {
792 const char ch = buffer[i];
793 str += hex_chars[(ch & 0xF0) >> 4];
794 str += hex_chars[(ch & 0x0F) >> 0];
795 }
796 BOOST_LOG_TRIVIAL(debug) << remote_endpoint.address()<< " " << str;
797#endif
798 // decode buffer, txt keys are not needed for A / AAAA answer
799 auto dns_msg = DnsMessage::decode(buffer, Bonjour::TxtKeys());
800 if (dns_msg) {
801 asio::ip::address ip;
802 std::string answer_name;
803 if (dns_msg->rr_a) {
804 ip = dns_msg->rr_a->ip;
805 answer_name = dns_msg->rr_a->name;
806 }
807 else if (dns_msg->rr_aaaa) {
808 ip = dns_msg->rr_aaaa->ip;
809 answer_name = dns_msg->rr_aaaa->name;
810 }
811 else
812 return; // not matching query type with answer type
813
814 if (!answer_name.empty()) {
815 // transform both strings to lower. Should we really do it?
816 std::string name_tolower = answer_name;
817 std::transform(name_tolower.begin(), name_tolower.end(), name_tolower.begin(),
818 [](unsigned char c) { return std::tolower(c); });
819 std::string hostname_tolower = socket->get_hostname();
820 std::transform(hostname_tolower.begin(), hostname_tolower.end(), hostname_tolower.begin(),
821 [](unsigned char c) { return std::tolower(c); });
822 if (name_tolower == hostname_tolower) {
823 BonjourReply reply(ip, 0, std::string(), answer_name, BonjourReply::TxtData());
824 replyfn(std::move(reply));
825 }
826 }
827 }
828}
std::set< std::string > TxtKeys
Definition Bonjour.hpp:57
std::string get_hostname() const
Definition Bonjour.hpp:261
boost::asio::ip::udp::endpoint remote_endpoint
Definition Bonjour.hpp:120
std::vector< char > buffer
Definition Bonjour.hpp:119
Bonjour::ReplyFn replyfn
Definition Bonjour.hpp:122
std::unordered_map< std::string, std::string > TxtData
Definition Bonjour.hpp:23
static optional< DnsMessage > decode(const std::vector< char > &buffer, const Bonjour::TxtKeys &txt_keys)
Definition Bonjour.cpp:406
static char error[256]
Definition tga.cpp:50

References Slic3r::UdpSession::buffer, Slic3r::DnsMessage::decode(), error, Slic3r::ResolveSocket::get_hostname(), Slic3r::UdpSession::remote_endpoint, Slic3r::UdpSession::replyfn, and socket.

+ Here is the call graph for this function:

Member Data Documentation

◆ buffer

std::vector<char> Slic3r::UdpSession::buffer
inherited

◆ remote_endpoint

boost::asio::ip::udp::endpoint Slic3r::UdpSession::remote_endpoint
inherited

◆ replyfn

Bonjour::ReplyFn Slic3r::UdpSession::replyfn
protectedinherited

◆ socket

const ResolveSocket* Slic3r::ResolveSession::socket
protected

Referenced by handle_receive().


The documentation for this class was generated from the following files: