How do NodeSockets determine if a link between them is possible?
Here's a rough proof-of-concept: https://gist.github.com/Theverat/f6c30469e22e03202dd429fe19b24c83
See my revision for the changes I did: https://gist.github.com/Theverat/f6c30469e22e03202dd429fe19b24c83/revisions

Basically, the node tree offers an update method which does not tell you what exactly happened, only that something happened.

But each node offers an insert_link method, which tells you about a link before it is inserted. So in this method you can not delete the link, or prevent it being inserted, you can only log it in your nodetree as new (or flag it for deletion).

So when the user creates a new link, this is what happens behind the scenes:


insert_link is called on the node the connection is coming from
insert_link is called on the node the connection is going into (Note: the link is the same, so you should prevent a duplicate insertion into the list of new links in the node tree)
update is called on the parent node tree of these nodes