AllJoyn: Get well-known name from announced About message? - java

Is it possible in AllJoyn to get the well-known name of a remote device from its announced About message? I would like to use the well-known name to connect to the device later on without a new discovery process.
I know I can get the device ID from the About message, but the well-known name seems to be different:
DeviceID: 558591fa-97db-464f-a8fa-efa30ecacc17
Actual Well-known name: net.allplay.MediaPlayer.i558591fa-97db-464f-a8fa-efa30ecacc17.r3X5_6mxu
While I could hard-code the beginning, I cannot find the last part (r3X5_6mxu) in the About message. Am I looking in the wrong place or is this information just not available?

Not from the announced About message.
When your app receives an announcement, your registered AboutListener's announced() method is called:
announced(String busName, int version, short port,
AboutObjectDescription[] objectDescriptions, Map<String, Variant> aboutData)
The busName parameter is mentioned in the javadoc as being the well-known name of the remote attachment, but in my experience the busName value has been the remote attachment's unique name. And the aboutData Map parameter does not contain the well-know name nor the unique name of the remote attachment (as far as standard fields in the aboutData map are concerned).
However, if you wish to correlate the remote attachment's well-known to its unique name (assuming a well-known name is published), then perhaps you could implement the BusListener interface and register it on your local bus. Each time the remote attachment has a name change, the following BusListener method is called in your app:
nameOwnerChanged(String busName, String previousOwner, String newOwner)
The busName parameter can be the remote attachment's well-known name (if it has one, otherwise it will be its unique name). For example, when the remote attachment is first established and assigned a name, a nameOwnerChanged message is sent (received by your app) with previousOwner=NULL and newOwner=[UniqueName]. Or when the remote attachment is terminated, for example, a nameOwnerChanged message is sent with previousOwner=[UniqueName] and newOwner=NULL. In this way you can see the remote attachment's busName and associated newOwner value.
Register interest in listening for remote well-known name prefix by calling findAdvertisedName(String namePrefix) on your local BusAttachment.

Related

send email to generic ID in lotus notes using notesFactory in java

Their is a requirement in a project to send emails from java application through lotus notes.
Note: the domino server is installed on client server.
Currently i am able to send email using notesFactory on my local machine.using notes.jar file
Which accesses the user by .nsf by its password.
I.e creating secure connection by password.
And gtting database object by calling
Session.getdatabase(null,"user.nsf")
Its perfectly working.
But for some types of emails the client have shared a generic id...(link) over an email... By clicking on that link the generic mail box opens under active user. In separate tab... Through which we can send emails.
But have not shared their .nsf path or id or password.
It directly opens by clicking on that link.
Now i want to access that generic id in notesfactory session
I tried to keep open that id and then running my code...but still it sends email through active user itself.
And client is not ready to share the id and password details of that user. Not the id file is getting generated in our local machine.
Is their any way to send emails through that id?
If anyone want code i am using..ill share.
But for some types of emails the client have shared a generic
id...(link) over an email... By clicking on that link the generic mail
box opens under active user. In separate tab... Through which we can
send emails.
That does not sound like a "shared id", it sounds more like a mail database with the ACL set to give a group of users access.
When you send an email from within Notes (no matter if it is through the UI or through code), the actual logged in user is used as the sender. It is intentionally by design, to prevent users from spoofing the sender.
There is an unsupported way to fake the sender address, by dropping the email directly into mail.box, but that should only be done by someone know what they are doing.
I wrote a script library several years ago, intended to help sending emails. It includes the ability to set the sender address. You can find it on my blog, it's free to use. But I would not recommend you using it without first understanding what the code is doing.
Here is the relevant part of the code:
Set mailbox = New NotesDatabase(mailservername,"mail.box")
If mailbox.Isopen = False Then
Print "mail.box on " & mailservername & " could not be opened"
Exit Sub
End If
Set me.maildoc = New NotesDocument(mailbox)
Call me.maildoc.ReplaceItemValue("Form","Memo")
Set me.body = New NotesRichTextItem(maildoc,"Body")
Call maildoc.ReplaceItemValue("Principal", me.p_principal)
' If principal is set, we want to fix so mail looks like
' it is coming from that address, need to set these fields
Call maildoc.ReplaceItemValue("From", me.p_principal)
Call maildoc.ReplaceItemValue("Sender", me.p_principal)
Call maildoc.ReplaceItemValue("ReplyTo", me.p_principal)
Call maildoc.ReplaceItemValue("SMTPOriginator", me.p_principal)
Call maildoc.ReplaceItemValue("PostedDate",Now())
If me.p_principal<>"" Then
Call maildoc.Save(True,False) ' Save in mail.box
Else
Call maildoc.Send(True) ' Send mail normally
End If
You use the Principal field to set the sender address.

Setting address manually on JGroups

I'd like to create a simple chat application where the user can send message to a specific user. Based on this answer, I can send a message to a specific target using the target's address. The problem is, I can't get a specific user address without tracking his id on the channel's view. Is there anyway to set a user address so I can generate a unique address for each registered user and then use it as their address each time they try to login? With that, I can get their address based their username from data storage.

Paho client for java generating folder like paho101658642587966-tcp1270011883. what is the importance of this?

I am using Paho client for java to connect to activeMq over mqtt. I noticed one strange thing. There are several folder created having names like "paho101658642587966-tcp1270011883" and having empty .lck files. Why are these used and when are they created.
These files are created to store inflight messages for QOS2 message before their delivery to the broker can be confirmed.
They are created by the MQTTDefaultFilePersistence class, you can change the directory name and path by creating your own MQTTDefaultFilePresistence object and passing it to the MQTTClient constructor.
You can also switch to a in memory store, but this will change how QOS2 messages are handled if the client crashes before a delivery can be confirmed.
You can specify the /tmp directory for client execution as:
String receiverId = UUID.randomUUID().toString();
IMqttClient receiver = new MqttClient(
"tcp://" + properties.getProperty("host") + ":" + properties.getProperty("port"), receiverId, new MqttDefaultFilePersistence("/tmp"));

Why is Java's InetAddress getHostName() not giving me the host's name?

I'm trying to get the device's name using its local IP address on the network. Is this how I'm supposed to do it? ex) Arnold-PC, andoid-nnnnnnnnnn
String name = InetAddress.getByName(ip).getHostName();
System.out.println(name);
The above should give me the host's name... but instead gives me the local IP address. - 192.168.2.101
as per the documentation...
public String getHostName ()
Returns the host name corresponding to this IP address. This may or
may not be a fully-qualified name. If the IP address could not be
resolved, the numeric representation is returned instead
Why is it not able to find the host's name?
I don't know much about computer networking... so please excuse my ignorance. :P
check in the command prompt whether you can able to resolve the ip address using nsloookup
if you can't, then your DNS broken
I would like to quote the few lines from java documentation here
getCanonicalHostName() Gets the fully qualified domain name for this
IP address. Best effort method, meaning we may not be able to return
the FQDN depending on the underlying system configuration.
one more trick is to edit host file to get output (not recommended)
Have a look in this answer too
link
From the docs
If this InetAddress was created with a host name, this host name will be remembered and returned; otherwise, a reverse name lookup will be performed and the result will be returned based on the system configured name lookup service. If a lookup of the name service is required, call getCanonicalHostName.
It seems like plain getHostName() won't look up the name if it can't reach out to a DNS server. The DNS server is what will give a name to the host IP address, just like a phone book. Give getCanonicalHostName() a try.

How to figure out an IPv6 address (by name) of a host in my LAN

I have two computers plugged in the same router of a network which I know supports IPv6. Let's call them "PC-A" and "PC-B
I want "PC-A" to figure out "PC-B"s IPv6 address and vice-versa
The first thing I do is
setSystem.setProperty("java.net.preferIPv6Addresses", "true");
If I then say
InetAddress IPAddress = InetAddress.getLocalHost();
I can get my own address which will be in IpV6 format
However, neither of the following two statements gives me "PC-B"s IPv6 address:
Inet6Address IPAddress6 = (Inet6Address)InetAddress.getByName("PC-B");
InetAddress IPAddress = InetAddress.getByName("PC-B");
I also tried to import
import com.lavantech.net.dns.SimpleDNSLookup;
import com.lavantech.net.dns.DNSLookup
The first one I am using as:
SimpleDNSLookup d = new SimpleDNSLookup();
System.out.println(d.getInet6Address("PC-B"));
and the second one as:
DNSLookup dnsLookup = new DNSLookup("PC-B", DNSLookup.QTYPE_AAAA, DNSLookup.QCLASS_IN, 3000, null);
// Get all Address Records.
ResourceRecord[] ansRecords = dnsLookup.getAAAARecords();
System.out.println(ansRecords[0]);
none of which works.
I also tried to use the following
import org.xbill.DNS.*;
int type = Type.AAAA;
Name name = Name.fromString("PC-B");
Lookup lookup = new Lookup(name, type);
lookup.run();
int result = lookup.getResult();
Record[] answers = lookup.getAnswers();
System.out.println(answers[0]);
// (where, for brevity, i am skipping the parts where I check whether result == Lookup.SUCCESSFUL
Note that if I substitute "PC-B" for, say, "ipv6.google.com" I get all the desired results!
Also note that if I just use InetAddress and Type_A wherever applicable in the above approaches, my program returns "PC-B"s IPv4 address without problem.
What am I missing?
Any help is greatly appreciated!
Your question is -unfortunately- a yet unsolved network problem dealing with host discovery on a local subnet (regardless if that subnet has a router or not).
Your desired output is clearly an IPv6 address, but it is unclear what exactly your input is.
Let's focus on PC-B. How exactly do you identify PC-B? It clear that you call it "PC-B", but that name should be configured somewhere before your PC know that that's its name. Where exactly is that configured? Is that the hostname you set on PC-B itself, or is there a domain name server (DNS) where you have given that name? If it is the name in the DNS system, you can indeed query the DNS system for the AAAA record to get the IPv6 address, but you need the fully qualified domain name (FQDN). E.g. "PC-B.yourdomain.com" rather than just "PC-B".
If you know the MAC address of PC-B, you can use the neighbour discovery protocol (NDP) to find out the IP address of PC-B.
There are network protocols that allow PC-A and PC-B to announce their names themselves, once you configured them on the local machines. Such protocols are called "service discovery" protocols, and your options here are (1) multicast DNS (mDNS) and possibly DNS service discovery (DNS-SD) on top of that; or (2) Simple Service Discovery Protocol (SSDP) in UPnP on the other hand. The advantage is that some operating systems already implement this. E.g. if PC-B is a Mac OS X host, all you need to do is query DNS for "pc-b.local" to get the answer. Unfortunately, while implementations of mDNS exist for Linux (Avahi) and Windows (Bonjour), they're not installed by default. A third alternative is to write your own host discovery protocol, and have your hosts run that protocol.
Considerations are which platforms you want to support, if installing third-party software is an option, if the discovery needs to be secure (the above options are not, look into Secure Neighbour Discovery -SEND- if this is a concern), and what input you have in the first place (the hostname "PC-B", or the type of service that runs on PC-B, e.g. _http._tcp for a webserver).

Categories

Resources