You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
362
mcs/class/referencesource/System.Net/net/PeerToPeer/Cloud.cs
Normal file
362
mcs/class/referencesource/System.Net/net/PeerToPeer/Cloud.cs
Normal file
@@ -0,0 +1,362 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="Cloud.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
namespace System.Net.PeerToPeer
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Security.Permissions;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
/// <remarks>
|
||||
/// The Cloud class directly represents the native cloud concept in the P2P APIs
|
||||
/// There are two special static readonly members we support
|
||||
/// Cloud.All and Cloud.AllLinkLocal
|
||||
/// Cloud.All is really a notational convinience of null in the native world
|
||||
/// Cloud.AllLinkLocal is equivalent to PEER_PNRP_ALL_LINK_CLOUDS const in the header file (declared in p2p.h)
|
||||
///
|
||||
/// This class is serializable.
|
||||
/// This class is not sealed because there is no reason for it to be sealed.
|
||||
/// </remarks>
|
||||
/// <
|
||||
|
||||
|
||||
|
||||
|
||||
[Serializable]
|
||||
public class Cloud : ISerializable, IEquatable<Cloud>
|
||||
{
|
||||
private const string PEER_PNRP_ALL_LINK_CLOUDS = "PEER_PNRP_ALL_LINKS";
|
||||
|
||||
private string m_CloudName; //name of the cloud
|
||||
private PnrpScope m_PnrpScope; //scope of the cloud
|
||||
private int m_ScopeId; //scope Id of the scope
|
||||
|
||||
/// <summary>
|
||||
/// Cloud.AllAvailable is a notational convinience. The native side uses a null for cloud parameter
|
||||
/// to indicate all clouds.
|
||||
/// </summary>
|
||||
public static readonly Cloud Available = new Cloud("AllAvailable", PnrpScope.All, -1);
|
||||
|
||||
/// <summary>
|
||||
/// AllLinkLocal is a managed abstraction of the native const PEER_PNRP_ALL_LINK_CLOUDS
|
||||
/// </summary>
|
||||
public static readonly Cloud AllLinkLocal = new Cloud("AllLinkLocal", PnrpScope.LinkLocal, -1);
|
||||
|
||||
/// <summary>
|
||||
/// The static constructor serves the purpose of checking the
|
||||
/// availability of the P2P apis on this platform
|
||||
/// </summary>
|
||||
static Cloud()
|
||||
{
|
||||
//-------------------------------------------------
|
||||
//Check for the availability of the simpler PNRP APIs
|
||||
//-------------------------------------------------
|
||||
if (!PeerToPeerOSHelper.SupportsP2P)
|
||||
{
|
||||
throw new PlatformNotSupportedException(SR.GetString(SR.P2P_NotAvailable));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an instance of a Cloud.
|
||||
/// This is not public and accessible for internal members only
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the cloud</param>
|
||||
/// <param name="pnrpScope">scope</param>
|
||||
/// <param name="scopeId">id ofthe scope</param>
|
||||
internal Cloud(string name, PnrpScope pnrpScope, int scopeId) {
|
||||
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "Creating cloud with Name: {0}, PnrpScope: {1}, ScopeID: {2}", name, pnrpScope, scopeId);
|
||||
m_CloudName = name;
|
||||
m_PnrpScope = pnrpScope;
|
||||
m_ScopeId = scopeId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Name
|
||||
/// </summary>
|
||||
public string Name {
|
||||
get {
|
||||
if (this == Cloud.AllLinkLocal || this == Cloud.Available)
|
||||
return null;
|
||||
return m_CloudName;
|
||||
}
|
||||
}
|
||||
|
||||
internal string InternalName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this == Cloud.AllLinkLocal)
|
||||
return PEER_PNRP_ALL_LINK_CLOUDS;
|
||||
else if (this == Cloud.Available)
|
||||
return null;
|
||||
return m_CloudName;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scope
|
||||
/// </summary>
|
||||
public PnrpScope Scope {
|
||||
get {
|
||||
return m_PnrpScope;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ScopeId
|
||||
/// </summary>
|
||||
public int ScopeId {
|
||||
get {
|
||||
return m_ScopeId;
|
||||
}
|
||||
}
|
||||
|
||||
public static Cloud Global
|
||||
{
|
||||
// <SecurityKernel Critical="True" Ring="1">
|
||||
// <ReferencesCritical Name="Method: GetCloudOrClouds(String, Boolean, CloudCollection&, Cloud&):Void" Ring="1" />
|
||||
// </SecurityKernel>
|
||||
//[System.Security.SecurityCritical]
|
||||
get
|
||||
{
|
||||
//throw new PeerToPeerException(SR.GetString(SR.Collab_SubscribeLocalContactFailed));
|
||||
CloudCollection dummy = null;
|
||||
Cloud cloud = null;
|
||||
GetCloudOrClouds(null, true, out dummy, out cloud);
|
||||
return cloud;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// <SecurityKernel Critical="True" Ring="1">
|
||||
// <ReferencesCritical Name="Method: GetCloudOrClouds(String, Boolean, CloudCollection&, Cloud&):Void" Ring="1" />
|
||||
// </SecurityKernel>
|
||||
//[System.Security.SecurityCritical]
|
||||
public static Cloud GetCloudByName(string cloudName)
|
||||
{
|
||||
if (cloudName == null || cloudName.Length == 0)
|
||||
{
|
||||
throw new ArgumentException(SR.GetString(SR.Pnrp_CloudNameCantBeNull), "cloudName");
|
||||
}
|
||||
CloudCollection dummy = null;
|
||||
Cloud cloud = null;
|
||||
GetCloudOrClouds(cloudName, false, out dummy, out cloud);
|
||||
return cloud;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The static member returns the list of clouds
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
// <SecurityKernel Critical="True" Ring="1">
|
||||
// <ReferencesCritical Name="Method: GetCloudOrClouds(String, Boolean, CloudCollection&, Cloud&):Void" Ring="1" />
|
||||
// </SecurityKernel>
|
||||
//[System.Security.SecurityCritical]
|
||||
public static CloudCollection GetAvailableClouds()
|
||||
{
|
||||
CloudCollection clouds = null;
|
||||
Cloud dummy = null;
|
||||
GetCloudOrClouds(null, false, out clouds, out dummy);
|
||||
return clouds;
|
||||
}
|
||||
|
||||
// <SecurityKernel Critical="True" Ring="0">
|
||||
// <CallsSuppressUnmanagedCode Name="UnsafeP2PNativeMethods.PeerPnrpGetCloudInfo(System.UInt32&,System.Net.PeerToPeer.SafePeerData&):System.Int32" />
|
||||
// <SatisfiesLinkDemand Name="SafeHandle.DangerousGetHandle():System.IntPtr" />
|
||||
// <SatisfiesLinkDemand Name="Marshal.PtrToStructure(System.IntPtr,System.Type):System.Object" />
|
||||
// <SatisfiesLinkDemand Name="Marshal.PtrToStringUni(System.IntPtr):System.String" />
|
||||
// <SatisfiesLinkDemand Name="Marshal.SizeOf(System.Type):System.Int32" />
|
||||
// <SatisfiesLinkDemand Name="SafeHandle.Dispose():System.Void" />
|
||||
// <ReferencesCritical Name="Local ArrayOfCloudInfoStructures of type: SafePeerData" Ring="1" />
|
||||
// <ReferencesCritical Name="Method: UnsafeP2PNativeMethods.PnrpStartup():System.Void" Ring="1" />
|
||||
// <ReferencesCritical Name="Method: PeerToPeerException.CreateFromHr(System.String,System.Int32):System.Net.PeerToPeer.PeerToPeerException" Ring="1" />
|
||||
// </SecurityKernel>
|
||||
[SuppressMessage("Microsoft.Security","CA2129:SecurityTransparentCodeShouldNotReferenceNonpublicSecurityCriticalCode", Justification="System.Net.dll is still using pre-v4 security model and needs this demand")]
|
||||
[System.Security.SecuritySafeCritical]
|
||||
private static void GetCloudOrClouds(string cloudName, bool bGlobalCloudOnly, out CloudCollection clouds, out Cloud cloud)
|
||||
{
|
||||
cloud = null;
|
||||
clouds = null;
|
||||
|
||||
Logging.Enter(Logging.P2PTraceSource, "Cloud::GetCloudOrClouds()");
|
||||
|
||||
//-------------------------------------------------
|
||||
//Demand for the Unrestricted Pnrp Permission
|
||||
//-------------------------------------------------
|
||||
PnrpPermission.UnrestrictedPnrpPermission.Demand();
|
||||
|
||||
Int32 result = 0;
|
||||
UInt32 numClouds = 0;
|
||||
SafePeerData ArrayOfCloudInfoStructures = null;
|
||||
if (cloudName == null)
|
||||
{
|
||||
//-----------------------------------------
|
||||
//We need the collection only when we are not
|
||||
//getting a specific cloud
|
||||
//-----------------------------------------
|
||||
clouds = new CloudCollection();
|
||||
}
|
||||
try
|
||||
{
|
||||
//---------------------------------------------------------------
|
||||
//No perf hit here, real native call happens only one time if it
|
||||
//did not already happen
|
||||
//---------------------------------------------------------------
|
||||
UnsafeP2PNativeMethods.PnrpStartup();
|
||||
|
||||
result = UnsafeP2PNativeMethods.PeerPnrpGetCloudInfo(out numClouds, out ArrayOfCloudInfoStructures);
|
||||
if (result != 0)
|
||||
{
|
||||
throw PeerToPeerException.CreateFromHr(SR.GetString(SR.Pnrp_CouldNotEnumerateClouds), result);
|
||||
}
|
||||
if (numClouds != 0)
|
||||
{
|
||||
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "Number of clouds returned {0}", numClouds);
|
||||
IntPtr pPEER_PNRP_CLOUD_INFO = ArrayOfCloudInfoStructures.DangerousGetHandle();
|
||||
for (ulong i = 0; i < numClouds; i++)
|
||||
{
|
||||
PEER_PNRP_CLOUD_INFO cloudinfo = (PEER_PNRP_CLOUD_INFO)Marshal.PtrToStructure(pPEER_PNRP_CLOUD_INFO, typeof(PEER_PNRP_CLOUD_INFO));
|
||||
string nativeCloudName = Marshal.PtrToStringUni(cloudinfo.pwzCloudName);
|
||||
pPEER_PNRP_CLOUD_INFO = (IntPtr)((long)pPEER_PNRP_CLOUD_INFO + Marshal.SizeOf(typeof(PEER_PNRP_CLOUD_INFO)));
|
||||
Cloud c = new Cloud(nativeCloudName, (PnrpScope)((int)cloudinfo.dwScope), (int)cloudinfo.dwScopeId);
|
||||
if (cloudName == null && !bGlobalCloudOnly)
|
||||
{
|
||||
clouds.Add(c);
|
||||
continue;
|
||||
}
|
||||
//If a specific cloud by name is required, then test for name
|
||||
//note that scope is PnrpScope.All but we don't test that now
|
||||
if (cloudName != null && cloudName == nativeCloudName)
|
||||
{
|
||||
cloud = c;
|
||||
break;
|
||||
}
|
||||
|
||||
if (bGlobalCloudOnly && c.Scope == PnrpScope.Global)
|
||||
{
|
||||
cloud = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logging.P2PTraceSource.TraceEvent(TraceEventType.Warning, 0, "No Clouds returned from the native call");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (ArrayOfCloudInfoStructures != null)
|
||||
{
|
||||
ArrayOfCloudInfoStructures.Dispose();
|
||||
}
|
||||
}
|
||||
if (cloudName != null && cloud == null)
|
||||
{
|
||||
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "The specific cloud name {0} asked for is not found", cloudName);
|
||||
}
|
||||
Logging.Leave(Logging.P2PTraceSource, "Cloud::GetCloudOrClouds()");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Two Clouds are equal only when all of the information matches
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public bool Equals(Cloud other)
|
||||
{
|
||||
if (other == null) return false;
|
||||
return other.Name == Name && other.Scope == Scope && other.ScopeId == ScopeId;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null) return false;
|
||||
Cloud other = obj as Cloud;
|
||||
if (other == null)
|
||||
return false;
|
||||
return Equals(other);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// The hash code comes from just the cloud name - for no partular reason.
|
||||
/// This implementation seems sufficient - since the cloud names or typically
|
||||
/// unique
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return m_CloudName.GetHashCode();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A friendly string for the Cloud object
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("Cloud Name:");
|
||||
sb.Append(Name);
|
||||
sb.Append(" Scope:");
|
||||
sb.Append(Scope);
|
||||
sb.Append(" ScopeId:");
|
||||
sb.Append(ScopeId);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor to enable serialization
|
||||
/// </summary>
|
||||
/// <param name="serializationInfo"></param>
|
||||
/// <param name="streamingContext"></param>
|
||||
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
|
||||
protected Cloud(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
m_CloudName = info.GetString("_CloudName");
|
||||
m_PnrpScope = (PnrpScope)info.GetValue("_CloudScope", typeof(PnrpScope));
|
||||
m_ScopeId = info.GetInt32("_CloudScopeId");
|
||||
}
|
||||
|
||||
// <SecurityKernel Critical="True" Ring="0">
|
||||
// <SatisfiesLinkDemand Name="GetObjectData(SerializationInfo, StreamingContext):Void" />
|
||||
// </SecurityKernel>
|
||||
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase", Justification = "System.Net.dll is still using pre-v4 security model and needs this demand")]
|
||||
[System.Security.SecurityCritical]
|
||||
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter, SerializationFormatter = true)]
|
||||
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
GetObjectData(info, context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is made virtual so that derived types can be implemented correctly
|
||||
/// </summary>
|
||||
/// <param name="serializationInfo"></param>
|
||||
/// <param name="streamingContext"></param>
|
||||
[SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter = true)]
|
||||
protected virtual void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
//Name is tricky since it can be null for AllLinkLocal and Available clouds
|
||||
//but internally we represent them with non null strings
|
||||
//so we should use the property here
|
||||
info.AddValue("_CloudName", Name);
|
||||
info.AddValue("_CloudScope", m_PnrpScope);
|
||||
info.AddValue("_CloudScopeId", m_ScopeId);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CloudCollection.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
namespace System.Net.PeerToPeer
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
|
||||
[Serializable]
|
||||
public class CloudCollection : Collection<Cloud>
|
||||
{
|
||||
public CloudCollection() { }
|
||||
protected override void SetItem(int index, Cloud item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
throw new ArgumentNullException("item");
|
||||
}
|
||||
base.SetItem(index, item);
|
||||
}
|
||||
protected override void InsertItem(int index, Cloud item)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
throw new ArgumentNullException("item");
|
||||
}
|
||||
base.InsertItem(index, item);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CollabEnumTypes.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Net.PeerToPeer.Collaboration
|
||||
{
|
||||
//
|
||||
// Defines all the enums used by peer collaboration
|
||||
//
|
||||
|
||||
public enum PeerPresenceStatus
|
||||
{
|
||||
Offline = 0,
|
||||
OutToLunch,
|
||||
Away,
|
||||
BeRightBack,
|
||||
Idle,
|
||||
Busy,
|
||||
OnThePhone,
|
||||
Online
|
||||
}
|
||||
|
||||
public enum PeerScope
|
||||
{
|
||||
None = 0,
|
||||
NearMe,
|
||||
Internet,
|
||||
All = NearMe | Internet
|
||||
}
|
||||
|
||||
public enum PeerApplicationRegistrationType
|
||||
{
|
||||
CurrentUser = 0,
|
||||
AllUsers
|
||||
}
|
||||
|
||||
public enum PeerInvitationResponseType
|
||||
{
|
||||
Declined = 0,
|
||||
Accepted,
|
||||
Expired
|
||||
}
|
||||
|
||||
public enum PeerChangeType
|
||||
{
|
||||
Added = 0,
|
||||
Deleted,
|
||||
Updated
|
||||
}
|
||||
|
||||
public enum SubscriptionType
|
||||
{
|
||||
Blocked = 0,
|
||||
Allowed
|
||||
}
|
||||
|
||||
internal enum PeerCollabEventType
|
||||
{
|
||||
WatchListChanged = 1,
|
||||
EndPointChanged = 2,
|
||||
EndPointPresenceChanged = 3,
|
||||
EndPointApplicationChanged = 4,
|
||||
EndPointObjectChanged = 5,
|
||||
MyEndPointChanged = 6,
|
||||
MyPresenceChanged = 7,
|
||||
MyApplicationChanged = 8,
|
||||
MyObjectChanged = 9,
|
||||
PeopleNearMeChanged = 10,
|
||||
RequestStatusChanged = 11
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,76 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="PeerApplicationLaunchInfo.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Net.PeerToPeer.Collaboration
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Represents launch info that collab gives back for the running application.
|
||||
/// If this application has been started up via collab invitation then it gives
|
||||
/// back the details of that invitation.
|
||||
/// </summary>
|
||||
public class PeerApplicationLaunchInfo
|
||||
{
|
||||
private PeerContact m_peerContact;
|
||||
private PeerEndPoint m_peerEndPoint;
|
||||
private PeerApplication m_peerApplication;
|
||||
private byte[] m_inviteData;
|
||||
private string m_message;
|
||||
|
||||
internal PeerApplicationLaunchInfo() { }
|
||||
|
||||
public PeerContact PeerContact
|
||||
{
|
||||
get{
|
||||
return m_peerContact;
|
||||
}
|
||||
internal set{
|
||||
m_peerContact = value;
|
||||
}
|
||||
}
|
||||
|
||||
public PeerEndPoint PeerEndPoint
|
||||
{
|
||||
get{
|
||||
return m_peerEndPoint;
|
||||
}
|
||||
internal set{
|
||||
m_peerEndPoint = value;
|
||||
}
|
||||
}
|
||||
|
||||
public PeerApplication PeerApplication
|
||||
{
|
||||
get{
|
||||
return m_peerApplication;
|
||||
}
|
||||
internal set{
|
||||
m_peerApplication = value;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] Data
|
||||
{
|
||||
get{
|
||||
return m_inviteData;
|
||||
}
|
||||
internal set{
|
||||
m_inviteData = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string Message
|
||||
{
|
||||
get{
|
||||
return m_message;
|
||||
}
|
||||
internal set{
|
||||
m_message = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,204 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="PeerCollaborationPermission.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Net.PeerToPeer.Collaboration
|
||||
{
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
using System.Globalization;
|
||||
|
||||
/// <remarks>
|
||||
/// PeerCollaborationPermissionAttribute atrribute
|
||||
/// </remarks>
|
||||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor |
|
||||
AttributeTargets.Class | AttributeTargets.Struct |
|
||||
AttributeTargets.Assembly,
|
||||
AllowMultiple = true, Inherited = false)]
|
||||
[Serializable()]
|
||||
public sealed class PeerCollaborationPermissionAttribute : CodeAccessSecurityAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Just call base constructor
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
public PeerCollaborationPermissionAttribute(SecurityAction action) : base(action) { }
|
||||
|
||||
/// <summary>
|
||||
/// As required by the SecurityAttribute class.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override IPermission CreatePermission()
|
||||
{
|
||||
if (Unrestricted){
|
||||
return new PeerCollaborationPermission(PermissionState.Unrestricted);
|
||||
}
|
||||
else{
|
||||
return new PeerCollaborationPermission(PermissionState.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// Currently we only support two levels - Unrestrictred or none
|
||||
/// </remarks>
|
||||
[Serializable]
|
||||
public sealed class PeerCollaborationPermission : CodeAccessPermission, IUnrestrictedPermission
|
||||
{
|
||||
private bool m_noRestriction;
|
||||
|
||||
internal static readonly PeerCollaborationPermission UnrestrictedPeerCollaborationPermission =
|
||||
new PeerCollaborationPermission(PermissionState.Unrestricted);
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// Creates a new instance of the <see cref='System.Net.PeerToPeer.Collaboration.PeerCollaborationPermission'/>
|
||||
/// class that passes all demands or that fails all demands.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public PeerCollaborationPermission(PermissionState state)
|
||||
{
|
||||
m_noRestriction = (state == PermissionState.Unrestricted);
|
||||
}
|
||||
|
||||
internal PeerCollaborationPermission(bool free)
|
||||
{
|
||||
m_noRestriction = free;
|
||||
}
|
||||
|
||||
// IUnrestrictedPermission interface methods
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// Checks the overall permission state of the object.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public bool IsUnrestricted()
|
||||
{
|
||||
return m_noRestriction;
|
||||
}
|
||||
|
||||
// IPermission interface methods
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// Creates a copy of a <see cref='System.Net.PeerToPeer..Collaboration.PeerCollaborationPermission'/> instance.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public override IPermission Copy()
|
||||
{
|
||||
if (m_noRestriction)
|
||||
return new PeerCollaborationPermission(true);
|
||||
else
|
||||
return new PeerCollaborationPermission(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Returns the logical union between two <see cref='System.Net.PeerToPeer..Collaboration.PeerCollaborationPermission'/> instances.</para>
|
||||
/// </summary>
|
||||
public override IPermission Union(IPermission target)
|
||||
{
|
||||
// Pattern suggested by Security engine
|
||||
if (target == null){
|
||||
return this.Copy();
|
||||
}
|
||||
PeerCollaborationPermission other = target as PeerCollaborationPermission;
|
||||
if (other == null){
|
||||
throw new ArgumentException(SR.GetString(SR.Collab_PermissionUnionError), "target");
|
||||
}
|
||||
return new PeerCollaborationPermission(m_noRestriction || other.m_noRestriction);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Returns the logical intersection between two <see cref='System.Net.PeerToPeer..Collaboration.PeerCollaborationPermission'/> instances.</para>
|
||||
/// </summary>
|
||||
public override IPermission Intersect(IPermission target)
|
||||
{
|
||||
// Pattern suggested by Security engine
|
||||
if (target == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
PeerCollaborationPermission other = target as PeerCollaborationPermission;
|
||||
if (other == null){
|
||||
throw new ArgumentException(SR.GetString(SR.Collab_PermissionIntersectError), "target");
|
||||
}
|
||||
|
||||
// return null if resulting permission is restricted and empty
|
||||
// Hence, the only way for a bool permission will be.
|
||||
if (this.m_noRestriction && other.m_noRestriction){
|
||||
return new PeerCollaborationPermission(true);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>Compares two <see cref='System.Net.PeerToPeer..Collaboration.PeerCollaborationPermission'/> instances.</para>
|
||||
/// </summary>
|
||||
public override bool IsSubsetOf(IPermission target)
|
||||
{
|
||||
// Pattern suggested by Security engine
|
||||
if (target == null){
|
||||
return m_noRestriction == false;
|
||||
}
|
||||
|
||||
PeerCollaborationPermission other = target as PeerCollaborationPermission;
|
||||
if (other == null){
|
||||
throw new ArgumentException(SR.GetString(SR.Collab_BadPermissionTarget), "target");
|
||||
}
|
||||
|
||||
//Here is the matrix of result based on m_noRestriction for me and she
|
||||
// me.noRestriction she.noRestriction me.isSubsetOf(she)
|
||||
// 0 0 1
|
||||
// 0 1 1
|
||||
// 1 0 0
|
||||
// 1 1 1
|
||||
return (!m_noRestriction || other.m_noRestriction);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy from a security element
|
||||
/// </summary>
|
||||
/// <param name="securityElement"></param>
|
||||
public override void FromXml(SecurityElement e)
|
||||
{
|
||||
if (e == null){
|
||||
throw new ArgumentNullException("e");
|
||||
}
|
||||
|
||||
// SecurityElement must be a permission element
|
||||
if (!e.Tag.Equals("IPermission"))
|
||||
{
|
||||
throw new ArgumentException(SR.GetString(SR.InvalidSecurityElem), "e");
|
||||
}
|
||||
string className = e.Attribute("class");
|
||||
// SecurityElement must be a permission element for this type
|
||||
if (className == null){
|
||||
throw new ArgumentException(SR.GetString(SR.InvalidSecurityElemNoClass), "e");
|
||||
}
|
||||
|
||||
if (className.IndexOf(this.GetType().FullName, StringComparison.Ordinal) < 0){
|
||||
throw new ArgumentException(SR.GetString(SR.InvalidSecurityElemNoType), "e");
|
||||
}
|
||||
string str = e.Attribute("Unrestricted");
|
||||
m_noRestriction = (str != null ? (0 == string.Compare(str, "true", StringComparison.OrdinalIgnoreCase)) : false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copyto a security element
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override SecurityElement ToXml()
|
||||
{
|
||||
SecurityElement securityElement = new SecurityElement("IPermission");
|
||||
securityElement.AddAttribute("class", this.GetType().FullName + ", " + this.GetType().Module.Assembly.FullName.Replace('\"', '\''));
|
||||
securityElement.AddAttribute("version", "1");
|
||||
|
||||
if (m_noRestriction){
|
||||
securityElement.AddAttribute("Unrestricted", "true");
|
||||
}
|
||||
return securityElement;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
namespace System.Net.PeerToPeer.Collaboration
|
||||
{
|
||||
public class PeerInvitationResponse
|
||||
{
|
||||
private PeerInvitationResponseType m_peerInvResponseType;
|
||||
|
||||
internal PeerInvitationResponse() { }
|
||||
internal PeerInvitationResponse(PeerInvitationResponseType reponseType)
|
||||
{
|
||||
m_peerInvResponseType = reponseType;
|
||||
}
|
||||
|
||||
public PeerInvitationResponseType PeerInvitationResponseType
|
||||
{
|
||||
get{
|
||||
return m_peerInvResponseType;
|
||||
}
|
||||
internal set{
|
||||
m_peerInvResponseType = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,48 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="PeerPresenceInfo.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Net.PeerToPeer.Collaboration
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Encapsulates the presence information for a collab peer
|
||||
/// </summary>
|
||||
public class PeerPresenceInfo
|
||||
{
|
||||
private PeerPresenceStatus m_peerPresenceStatus;
|
||||
private string m_descriptiveText;
|
||||
|
||||
public PeerPresenceInfo() {}
|
||||
|
||||
public PeerPresenceInfo(PeerPresenceStatus presenceStatus, string description) {
|
||||
m_peerPresenceStatus = presenceStatus;
|
||||
m_descriptiveText = description;
|
||||
}
|
||||
|
||||
public PeerPresenceStatus PresenceStatus
|
||||
{
|
||||
get{
|
||||
return m_peerPresenceStatus;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_peerPresenceStatus = value;
|
||||
}
|
||||
}
|
||||
public string DescriptiveText
|
||||
{
|
||||
get{
|
||||
return m_descriptiveText;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_descriptiveText = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
593
mcs/class/referencesource/System.Net/net/PeerToPeer/PeerName.cs
Normal file
593
mcs/class/referencesource/System.Net/net/PeerToPeer/PeerName.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,196 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="PeerNameRecord.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
namespace System.Net.PeerToPeer
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Security.Permissions;
|
||||
using System.Net;
|
||||
[Serializable]
|
||||
public class PeerNameRecord : ISerializable
|
||||
{
|
||||
private const int MAX_COMMENT_SIZE = 39;
|
||||
private const int MAX_DATA_SIZE = 4096;
|
||||
|
||||
private PeerName m_PeerName;
|
||||
private IPEndPointCollection m_EndPointCollection = new IPEndPointCollection();
|
||||
private string m_Comment;
|
||||
private byte[] m_Data;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Constructor to enable serialization
|
||||
/// </summary>
|
||||
/// <param name="serializationInfo"></param>
|
||||
/// <param name="streamingContext"></param>
|
||||
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
|
||||
protected PeerNameRecord(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
m_Comment = info.GetString("_Comment");
|
||||
m_Data = info.GetValue("_Data", typeof(byte[])) as byte[];
|
||||
m_EndPointCollection = info.GetValue("_EndpointList", typeof(IPEndPointCollection)) as IPEndPointCollection;
|
||||
m_PeerName = info.GetValue("_PeerName", typeof(PeerName)) as PeerName;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// <SecurityKernel Critical="True" Ring="0">
|
||||
// <SatisfiesLinkDemand Name="GetObjectData(SerializationInfo, StreamingContext):Void" />
|
||||
// </SecurityKernel>
|
||||
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase", Justification = "System.Net.dll is still using pre-v4 security model and needs this demand")]
|
||||
[System.Security.SecurityCritical]
|
||||
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter, SerializationFormatter = true)]
|
||||
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
GetObjectData(info, context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is made virtual so that derived types can be implemented correctly
|
||||
/// </summary>
|
||||
/// <param name="serializationInfo"></param>
|
||||
/// <param name="streamingContext"></param>
|
||||
[SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter = true)]
|
||||
protected virtual void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
info.AddValue("_PeerName", m_PeerName);
|
||||
info.AddValue("_EndpointList", m_EndPointCollection);
|
||||
info.AddValue("_Comment", m_Comment);
|
||||
info.AddValue("_Data", m_Data);
|
||||
}
|
||||
|
||||
public PeerNameRecord()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
public PeerNameRecord(PeerName peerName)
|
||||
{
|
||||
m_PeerName = peerName;
|
||||
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "PeerNameRecord created with PeerName {0}", m_PeerName);
|
||||
}
|
||||
|
||||
public PeerNameRecord(PeerName peerName, int Port)
|
||||
{
|
||||
m_PeerName = peerName;
|
||||
m_Port = Port;
|
||||
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "PeerNameRecord created with PeerName {0} Port {1}", m_PeerName, m_Port);
|
||||
}
|
||||
|
||||
public PeerNameRecord(PeerName peerName, IPEndPoint[] endPointList, Cloud cloud, string comment, byte[] data)
|
||||
{
|
||||
m_PeerName = peerName;
|
||||
m_Port = Port;
|
||||
m_EndPointList = endPointList;
|
||||
m_Cloud = cloud;
|
||||
m_Comment = comment;
|
||||
m_Data = data;
|
||||
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "PeerNameRecord created");
|
||||
TracePeerNameRecord();
|
||||
}
|
||||
*/
|
||||
|
||||
public PeerName PeerName
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_PeerName;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_PeerName = value;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public IPEndPointCollection EndPointCollection
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_EndPointCollection;
|
||||
}
|
||||
}
|
||||
|
||||
public string Comment
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Comment;
|
||||
}
|
||||
set
|
||||
{
|
||||
//--------------------------------------------------------------------
|
||||
//We don't allow null or empty comments since they are not very useful
|
||||
//--------------------------------------------------------------------
|
||||
if (value == null)
|
||||
throw new ArgumentNullException("Comment", SR.GetString(SR.Pnrp_CommentCantBeNull));
|
||||
|
||||
if(value.Length <= 0)
|
||||
throw new ArgumentException(SR.GetString(SR.Pnrp_CommentCantBeNull), "Comment");
|
||||
|
||||
if (value.Length > MAX_COMMENT_SIZE)
|
||||
throw new ArgumentException(SR.GetString(SR.Pnrp_CommentMaxLengthExceeded, MAX_COMMENT_SIZE));
|
||||
|
||||
m_Comment = value;
|
||||
}
|
||||
}
|
||||
public byte[] Data
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
throw new ArgumentNullException("Data", SR.GetString(SR.Pnrp_DataCantBeNull));
|
||||
|
||||
if (value.Length <= 0)
|
||||
throw new ArgumentException(SR.GetString(SR.Pnrp_DataCantBeNull), "Data");
|
||||
|
||||
if(value.Length > MAX_DATA_SIZE)
|
||||
throw new ArgumentException(SR.GetString(SR.Pnrp_DataLengthExceeded, MAX_DATA_SIZE));
|
||||
|
||||
m_Data = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal void TracePeerNameRecord()
|
||||
{
|
||||
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "Contents of the PeerNameRecord");
|
||||
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "\tPeerName: {0}", PeerName);
|
||||
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "\tComment: {0}", Comment);
|
||||
if (EndPointCollection != null && EndPointCollection.Count != 0)
|
||||
{
|
||||
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "\tThe EndPointList is ");
|
||||
foreach(IPEndPoint ipe in EndPointCollection)
|
||||
{
|
||||
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "\t\tIPEndPoint is {0}", ipe);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "\tThe EndPointList is empty or null");
|
||||
}
|
||||
if (Data != null)
|
||||
{
|
||||
if (Logging.P2PTraceSource.Switch.ShouldTrace(TraceEventType.Verbose))
|
||||
{
|
||||
Logging.DumpData(Logging.P2PTraceSource, TraceEventType.Verbose, Logging.P2PTraceSource.MaxDataSize, Data, 0, Data.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logging.P2PTraceSource.TraceEvent(TraceEventType.Information, 0, "\tCustom data length {0}", Data.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user