google / eDistantObject

eDistantObject (eDO) - Remote invocation library for iOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Forward `isKindOfClass:` to distant object?

fumoboy007 opened this issue · comments

Is there a reason we are not forwarding isKindOfClass: to the distant object? I think that would make the most sense since users are more likely to want to check the class of the actual object than of the proxy. FWIW, NSDistantObject forwards.

If we forward -isKindOfClass: One problem is that the Class will become a remote object on the receiving side and will never succeed. We can make Class pass-by-value, however, is there a way to know the class linked in two processes are the same if only given the name or is there any way to check class integrity/equality?

Good question. I don’t know the answer, but perhaps we can look at how Apple does it?

we can look at how Apple does it?

It is a little convoluted to digest, this is one of the sources we used to learn in the past. You are welcome to take a look and send the PR, I am happy to review.

Findings

  1. NSDistantObject calls -[NSConnection forwardInvocation:forProxy:], which calls -[NSInvocation encodeWithDistantCoder:passPointers:] with an NSPortCoder.
  2. I am assuming -[NSInvocation encodeWithCoder:] is called after that, which encodes the arguments using the coder.
  3. In NSPortCoder, the whole inheritance hierarchy is serialized.
  4. For each class, the class name and the class version are serialized.

Great findings, thanks!

What do you think of implementing it in eDO? To encode a class, we record the entire hierarchy and their respective versions; to decode, we find the class name and attempt to match its local version and hierarchy, right? this sounds a reasonable start. How do you think of a coincidental client that has the same entire hierarchy but a different implementation? I think this odd is super low, but it can happen too, right?

the other question, what is class version, how do we make sure it's well maintained?

Thanks a lot for looking into this @fumoboy007. If class_getName can work across processes, then this would work for the cursory isKindOfClass comparison. My worry is how this would differ from an actual Class comparison itself.

Hmm not sure if we can really guarantee compatibility across processes. FWIW, Apple/GNUstep’s implementation just calls objc_lookUpClass. I don’t think it even checks the version or the hierarchy. If y’all are comfortable with doing that, I can implement it.

FWIW, Apple/GNUstep’s implementation just calls objc_lookUpClass.

After thinking about it, it should be fine because we are checking the class remote with a remote object. Suppose the client fakes a class by name, it would only cause the host to look it up.

If y’all are comfortable with doing that, I can implement it.

It will be great if you can implement it. Either Aditya, me or someone from our team can review it. There are another two things you might need to take a look:

  1. Class is handled differently by ARC, probably because it's static. you may need to pay extra attention to it.

  2. We have EDO_REMOTE_CLASS where you do need a remote Class, we need to make sure this behavior is not broken.