in proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java [1250:1330]
public void handleAttach(Attach attach, Binary payload, Integer channel)
{
TransportSession transportSession = _remoteSessions.get(channel);
if(transportSession == null)
{
// TODO - fail due to attach on non-begun session
}
else
{
SessionImpl session = transportSession.getSession();
final UnsignedInteger handle = attach.getHandle();
if (handle.compareTo(transportSession.getHandleMax()) > 0) {
// The handle-max value is the highest handle value that can be used on the session. A peer MUST
// NOT attempt to attach a link using a handle value outside the range that its partner can handle.
// A peer that receives a handle outside the supported range MUST close the connection with the
// framing-error error-code.
ErrorCondition condition =
new ErrorCondition(ConnectionError.FRAMING_ERROR,
"handle-max exceeded");
_connectionEndpoint.setCondition(condition);
_connectionEndpoint.setLocalState(EndpointState.CLOSED);
if (!_isCloseSent) {
Close close = new Close();
close.setError(condition);
_isCloseSent = true;
writeFrame(0, close, null, null);
}
close_tail();
return;
}
TransportLink<?> transportLink = transportSession.getLinkFromRemoteHandle(handle);
LinkImpl link = null;
if(transportLink != null)
{
// TODO - fail - attempt attach on a handle which is in use
}
else
{
// We flip the peer role to determine our local role, and try to resolve an existing half-open link
transportLink = transportSession.resolveHalfOpenLink(attach.getName(), Role.RECEIVER == attach.getRole());
if(transportLink == null)
{
link = (attach.getRole() == Role.RECEIVER)
? session.sender(attach.getName())
: session.receiver(attach.getName());
transportLink = getTransportState(link);
}
else
{
link = transportLink.getLink();
}
if(attach.getRole() == Role.SENDER)
{
transportLink.setDeliveryCount(attach.getInitialDeliveryCount());
}
link.setRemoteState(EndpointState.ACTIVE);
link.setRemoteSource(attach.getSource());
link.setRemoteTarget(attach.getTarget());
link.setRemoteReceiverSettleMode(attach.getRcvSettleMode());
link.setRemoteSenderSettleMode(attach.getSndSettleMode());
link.setRemoteProperties(attach.getProperties());
link.setRemoteDesiredCapabilities(attach.getDesiredCapabilities());
link.setRemoteOfferedCapabilities(attach.getOfferedCapabilities());
link.setRemoteMaxMessageSize(attach.getMaxMessageSize());
transportLink.setName(attach.getName());
transportLink.setRemoteHandle(handle);
transportSession.addLinkRemoteHandle(transportLink, handle);
}
_connectionEndpoint.put(Event.Type.LINK_REMOTE_OPEN, link);
}
}