/// <summary> /// Constructor /// </summary> /// <param name="config">Network configuration</param> /// <param name="aclLoader">ACL loader to define access</param> /// <param name="peerFactory">Factory to create peers from endpoints</param> /// <param name="peerListener">Listener to accept peer connections</param> /// <param name="peerMessageListener">PeerMessageListener</param> /// <param name="logger">Logger</param> public Server( NetworkConfig config, INetworkAclLoader aclLoader, IPeerFactory peerFactory, IPeerListener peerListener, IPeerMessageListener peerMessageListener, ILogger <Server> logger) { if (config == null) { throw new ArgumentNullException(nameof(config)); } _peerFactory = peerFactory ?? throw new ArgumentNullException(nameof(peerFactory)); _peerListener = peerListener ?? throw new ArgumentNullException(nameof(peerListener)); if (aclLoader == null) { throw new ArgumentNullException(nameof(aclLoader)); } _acl = aclLoader.Load(config.AclConfig) ?? NetworkAcl.Default; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _peerMessageListener = peerMessageListener ?? throw new ArgumentNullException(nameof(peerMessageListener)); _peerListener.OnPeerConnected += PeerConnected; _connectedPeers = new ConcurrentBag <IPeer>(); _failedPeers = new List <IPEndPoint>(); // TODO: Change after port forwarding implementation _peerEndPoints = config.PeerEndPoints; }
public void Start_PeerIsNotAllowed_WarningLoggedAndPeerDisconnected() { // Arrange var networkAcl = new NetworkAcl(NetworkAclType.Blacklist, new[] { new NetworkAcl.Entry("localhost") }); var networkAclLoaderMock = this.AutoMockContainer.GetMock <INetworkAclLoader>(); networkAclLoaderMock .Setup(x => x.Load(It.IsAny <NetworkAclConfig>())) .Returns(networkAcl); var loggerMock = this.AutoMockContainer.GetMock <ILogger <Server> >(); var peerMock = AutoMockContainer.GetMock <IPeer>(); peerMock .SetupGet(x => x.EndPoint) .Returns(_peerEndPoint); var peer = peerMock.Object; var peerFactoryMock = AutoMockContainer.GetMock <IPeerFactory>(); peerFactoryMock .Setup(x => x.ConnectTo(_peerEndPoint)) .Returns(Task.FromResult(peer)); var server = AutoMockContainer.Create <Server>(); // Act server.Start(); // Assert loggerMock.Verify(x => x.LogWarning(It.Is <string>(s => s.StartsWith("Something went wrong with "))), Times.Once); peerMock.Verify(x => x.Disconnect(), Times.Once); }
/// <summary> /// Constructor /// </summary> /// <param name="config">Network configuration</param> /// <param name="aclLoader">ACL loader to define access</param> /// <param name="peerFactory">Factory to create peers from endpoints</param> /// <param name="peerListener">Listener to accept peer connections</param> /// <param name="peerMessageListener">PeerMessageListener</param> /// <param name="serverContext">Server context</param> /// <param name="serverProcesses">Server processes</param> /// <param name="logger">Logger</param> public Server( NetworkConfig config, INetworkAclLoader aclLoader, IPeerFactory peerFactory, IPeerListener peerListener, IPeerMessageListener peerMessageListener, IServerContext serverContext, IEnumerable <IServerProcess> serverProcesses, ILogger <Server> logger) { if (config == null) { throw new ArgumentNullException(nameof(config)); } _peerFactory = peerFactory ?? throw new ArgumentNullException(nameof(peerFactory)); _peerListener = peerListener ?? throw new ArgumentNullException(nameof(peerListener)); if (aclLoader == null) { throw new ArgumentNullException(nameof(aclLoader)); } _acl = aclLoader.Load(config.AclConfig) ?? NetworkAcl.Default; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _peerMessageListener = peerMessageListener ?? throw new ArgumentNullException(nameof(peerMessageListener)); _serverContext = serverContext ?? throw new ArgumentNullException(nameof(serverContext)); _serverProcesses = serverProcesses ?? throw new ArgumentNullException(nameof(serverProcesses)); _peerListener.OnPeerConnected += PeerConnected; // TODO #364: Change after port forwarding implementation _peerEndPoints = config.PeerEndPoints; }
public void createModel(Package pkg, NetworkAcl acl) { // Get the model identifier string aclId = acl.NetworkAclId.ToString(); // Create the Route Table element Element element = pkg.Elements.AddNew(aclId, "Class"); element.Update(); // Keep it in the cache this.AwsModelCache.Add(aclId, element); }
/// <summary> /// Constructor /// </summary> /// <param name="config">Config</param> /// <param name="blockchain">Blockchain</param> /// <param name="logger">Logger</param> /// <param name="aclLoader">ACL Loader</param> public RpcServer( RpcConfig config, ILogger <RpcServer> logger, INetworkAclLoader aclLoader) { _config = config ?? throw new ArgumentNullException(nameof(config)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); if (aclLoader == null) { throw new ArgumentNullException(nameof(aclLoader)); } _acl = aclLoader.Load(config.AclConfig) ?? NetworkAcl.Default; InjectSpecialParameter(ctx => ctx); }
protected async Task <WebPubSub> CreateDefaultWebPubSub(string webPubSubName, Location location, ResourceGroup resourceGroup) { // Create WebPubSub ConfigData IList <LiveTraceCategory> categories = new List <LiveTraceCategory>() { new LiveTraceCategory("category-01", "true"), }; AclAction aclAction = new AclAction("Deny"); IList <WebPubSubRequestType> allow = new List <WebPubSubRequestType>(); IList <WebPubSubRequestType> deny = new List <WebPubSubRequestType>() { new WebPubSubRequestType("RESTAPI") }; NetworkAcl publicNetwork = new NetworkAcl(allow, deny); IList <PrivateEndpointAcl> privateEndpoints = new List <PrivateEndpointAcl>(); List <ResourceLogCategory> resourceLogCategory = new List <ResourceLogCategory>() { new ResourceLogCategory() { Name = "category1", Enabled = "false" } }; WebPubSubData data = new WebPubSubData(Location.WestUS2) { Sku = new WebPubSubSku("Standard_S1"), LiveTraceConfiguration = new LiveTraceConfiguration("true", categories), NetworkAcls = new WebPubSubNetworkAcls(aclAction, publicNetwork, privateEndpoints), ResourceLogConfiguration = new ResourceLogConfiguration(resourceLogCategory), }; // Create WebPubSub var webPubSub = await(await resourceGroup.GetWebPubSubs().CreateOrUpdateAsync(webPubSubName, data)).WaitForCompletionAsync(); return(webPubSub.Value); }
public async Task <WebPubSub> CreateWebPubSub() { // Create WebPubSub ConfigData IList <LiveTraceCategory> categories = new List <LiveTraceCategory>(); categories.Add(new LiveTraceCategory("category-01", "true")); AclAction aclAction = new AclAction("Deny"); IList <WebPubSubRequestType> allow = new List <WebPubSubRequestType>(); IList <WebPubSubRequestType> deny = new List <WebPubSubRequestType>(); //allow.Add(new WebPubSubRequestType("ClientConnectionValue")); deny.Add(new WebPubSubRequestType("RESTAPI")); NetworkAcl publicNetwork = new NetworkAcl(allow, deny); IList <PrivateEndpointAcl> privateEndpoints = new List <PrivateEndpointAcl>(); List <ResourceLogCategory> resourceLogCategory = new List <ResourceLogCategory>() { new ResourceLogCategory() { Name = "category1", Enabled = "false" } }; WebPubSubData data = new WebPubSubData(AzureLocation.WestUS2) { Sku = new WebPubSubSku("Standard_S1"), LiveTraceConfiguration = new LiveTraceConfiguration("true", categories), //EventHandler = new EventHandlerSettings(items), NetworkAcls = new WebPubSubNetworkAcls(aclAction, publicNetwork, privateEndpoints), ResourceLogConfiguration = new ResourceLogConfiguration(resourceLogCategory), }; // Create WebPubSub var webPubSub = await(await _resourceGroup.GetWebPubSubs().CreateOrUpdateAsync(true, _webPubSubName, data)).WaitForCompletionAsync(); return(webPubSub.Value); }
public async Task CreateOrUpdate() { #region Snippet:Managing_WebPubSub_CreateWebPubSub WebPubSubCollection WebPubSubColletion = resourceGroup.GetWebPubSubs(); string webPubSubName = "myWebPubSubName"; // Use the same location as the resource group IList <LiveTraceCategory> categories = new List <LiveTraceCategory>(); categories.Add(new LiveTraceCategory("category-01", "true")); AclAction aclAction = new AclAction("Deny"); IList <WebPubSubRequestType> allow = new List <WebPubSubRequestType>(); IList <WebPubSubRequestType> deny = new List <WebPubSubRequestType>(); deny.Add(new WebPubSubRequestType("RESTAPI")); NetworkAcl publicNetwork = new NetworkAcl(allow, deny); IList <PrivateEndpointAcl> privateEndpoints = new List <PrivateEndpointAcl>(); List <ResourceLogCategory> resourceLogCategory = new List <ResourceLogCategory>() { new ResourceLogCategory() { Name = "category1", Enabled = "false" } }; WebPubSubData data = new WebPubSubData(Location.WestUS2) { Sku = new WebPubSubSku("Standard_S1"), LiveTraceConfiguration = new LiveTraceConfiguration("true", categories), NetworkAcls = new WebPubSubNetworkAcls(aclAction, publicNetwork, privateEndpoints), ResourceLogConfiguration = new ResourceLogConfiguration(resourceLogCategory), }; WebPubSub webPubSub = await(await WebPubSubColletion.CreateOrUpdateAsync(webPubSubName, data)).WaitForCompletionAsync(); #endregion }
public CreateNetworkAclModelWorkItemImpl NewCreateNetworkAclModelWorkItem(Package pkg, NetworkAcl networkAcl) { CreateNetworkAclModelWorkItemImpl workItem = new CreateNetworkAclModelWorkItemImpl(); workItem.Pkg = pkg; workItem.NetworkAcl = networkAcl; return(workItem); }