OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::ResolveSession Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/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 ResolveSocket * socket
Bonjour::ReplyFn replyfn

Detailed Description

Constructor & Destructor Documentation

◆ ResolveSession()

Slic3r::ResolveSession::ResolveSession ( const ResolveSocket * sckt,
Bonjour::ReplyFn rfn )
inline
153: UdpSession(rfn), socket(sckt) {}
const ResolveSocket * socket
Definition Bonjour.hpp:157
UdpSession(Bonjour::ReplyFn rfn)
Definition Bonjour.cpp:640

References Slic3r::UdpSession::UdpSession(), and socket.

Here is the call graph for this function:

Member Function Documentation

◆ handle_receive()

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

Implements Slic3r::UdpSession.

797{
798 assert(socket);
799 if (error) {
800 // todo: what level? do we even log? There might be callbacks when timer runs out
801 BOOST_LOG_TRIVIAL(info) << error.message();
802 return;
803 }
804 if (bytes == 0 || !replyfn) {
805 // todo: log something?
806 return;
807 }
808
809 buffer.resize(bytes);
810#if 0
811 std::string str;
812 char const hex_chars[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
813 for (size_t i = 0; i < buffer.size(); i++) {
814 const char ch = buffer[i];
815 str += hex_chars[(ch & 0xF0) >> 4];
816 str += hex_chars[(ch & 0x0F) >> 0];
817 }
818 BOOST_LOG_TRIVIAL(debug) << remote_endpoint.address()<< " " << str;
819#endif
820 // decode buffer, txt keys are not needed for A / AAAA answer
821 auto dns_msg = DnsMessage::decode(buffer, Bonjour::TxtKeys());
822 if (dns_msg) {
823 asio::ip::address ip;
824 std::string answer_name;
825 if (dns_msg->rr_a) {
826 ip = dns_msg->rr_a->ip;
827 answer_name = dns_msg->rr_a->name;
828 }
829 else if (dns_msg->rr_aaaa) {
830 ip = dns_msg->rr_aaaa->ip;
831 answer_name = dns_msg->rr_aaaa->name;
832 }
833 else
834 return; // not matching query type with answer type
835
836 if (!answer_name.empty()) {
837 // transform both strings to lower. Should we really do it?
838 std::string name_tolower = answer_name;
839 std::transform(name_tolower.begin(), name_tolower.end(), name_tolower.begin(),
840 [](unsigned char c) { return std::tolower(c); });
841 std::string hostname_tolower = socket->get_hostname();
842 std::transform(hostname_tolower.begin(), hostname_tolower.end(), hostname_tolower.begin(),
843 [](unsigned char c) { return std::tolower(c); });
844 if (name_tolower == hostname_tolower) {
845 BonjourReply reply(ip, 0, std::string(), answer_name, BonjourReply::TxtData());
846 replyfn(std::move(reply));
847 }
848 }
849 }
850}
std::set< std::string > TxtKeys
Definition Bonjour.hpp:70
boost::asio::ip::udp::endpoint remote_endpoint
Definition Bonjour.hpp:134
std::vector< char > buffer
Definition Bonjour.hpp:133
Bonjour::ReplyFn replyfn
Definition Bonjour.hpp:136
std::unordered_map< std::string, std::string > TxtData
Definition Bonjour.hpp:36
static optional< DnsMessage > decode(const std::vector< char > &buffer, const Bonjour::TxtKeys &txt_keys)
Definition Bonjour.cpp:428

References Slic3r::UdpSession::buffer, Slic3r::DnsMessage::decode(), 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 ResolveSession(), and handle_receive().


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/Bonjour.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/Bonjour.cpp