The following two lines are terrible:
return cast(int, peerInfo & PeerInfo.Connected) != 0
peerInfo &= cast(PeerInfo, ~cast(int, PeerInfo.Connected))
The proper way is:
return peerInfo & PeerInfo.Connected != 0
peerInfo &= ~PeerInfo.Connected
The second line issue is now being tracked as BOO-617.