Beispiel #1
0
        /// <summary>
        /// Creates a new instance of a profile server.
        /// </summary>
        /// <param name="Name">Unique profile server instance name.</param>
        /// <param name="Location">GPS location of this profile server instance.</param>
        /// <param name="Port">Base TCP port that defines the range of ports that are going to be used by this profile server instance and its related servers.</param>
        public ProfileServer(string Name, GpsLocation Location, int Port)
        {
            log = new PrefixLogger("ProfileServerSimulator.ProfileServer", "[" + Name + "] ");
            log.Trace("(Name:'{0}',Location:{1},Port:{2})", Name, Location, Port);

            this.name     = Name;
            this.location = Location;
            basePort      = Port;
            ipAddress     = IPAddress.Parse("127.0.0.1");

            locPort = basePort;
            primaryInterfacePort           = basePort + 1;
            serverNeighborInterfacePort    = basePort + 2;
            clientNonCustomerInterfacePort = basePort + 3;
            clientCustomerInterfacePort    = basePort + 4;
            clientAppServiceInterfacePort  = basePort + 5;

            availableIdentitySlots = MaxHostedIdentities;
            hostedIdentities       = new List <IdentityClient>();

            nodeLocation = new Iop.Locnet.GpsLocation()
            {
                Latitude  = Location.GetLocationTypeLatitude(),
                Longitude = Location.GetLocationTypeLongitude()
            };

            initializationNeighborhoodNotificationList = new HashSet <ProfileServer>();

            log.Trace("(-)");
        }
Beispiel #2
0
        /// <summary>
        /// Returns location network node information.
        /// </summary>
        /// <param name="LocPort">Port of the associated LOC server.</param>
        /// <returns>NodeInfo structure describing the server in location network.</returns>
        public Iop.Locnet.NodeInfo GetNodeInfo(int LocPort)
        {
            Iop.Locnet.NodeInfo res = new Iop.Locnet.NodeInfo()
            {
                NodeId   = ProtocolHelper.ByteArrayToByteString(new byte[0]),
                Location = new Iop.Locnet.GpsLocation()
                {
                    Latitude  = location.GetLocationTypeLatitude(),
                    Longitude = location.GetLocationTypeLongitude()
                },
                Contact = new Iop.Locnet.NodeContact()
                {
                    IpAddress  = ProtocolHelper.ByteArrayToByteString(ipAddress.GetAddressBytes()),
                    NodePort   = (uint)LocPort,
                    ClientPort = (uint)LocPort
                },
            };

            Iop.Locnet.ServiceInfo serviceInfo = new Iop.Locnet.ServiceInfo()
            {
                Type        = Iop.Locnet.ServiceType.Profile,
                Port        = (uint)primaryPort,
                ServiceData = ProtocolHelper.ByteArrayToByteString(Crypto.Sha256(keys.PublicKey))
            };

            res.Services.Add(serviceInfo);
            return(res);
        }
Beispiel #3
0
        /// <summary>
        /// Returns network profile information about the client's identity.
        /// </summary>
        /// <param name="IncludeThumbnailImage">If true, the returned profile information will include thumbnail image.</param>
        /// <returns>network profile information about the client's identity.</returns>
        public IdentityNetworkProfileInformation GetIdentityNetworkProfileInformation(bool IncludeThumbnailImage)
        {
            log.Trace("(IncludeThumbnailImage:{0})", IncludeThumbnailImage);

            IdentityNetworkProfileInformation res = new IdentityNetworkProfileInformation()
            {
                IdentityPublicKey = ProtocolHelper.ByteArrayToByteString(keys.PublicKey),
                IsHosted          = false,
                IsOnline          = false,
                Latitude          = location.GetLocationTypeLatitude(),
                Longitude         = location.GetLocationTypeLongitude(),
                Name      = name != null ? name : "",
                Type      = type != null ? type : "",
                Version   = version.ToByteString(),
                ExtraData = extraData != null ? extraData : ""
            };

            if (IncludeThumbnailImage && (thumbnailImage != null))
            {
                res.ThumbnailImage = ProtocolHelper.ByteArrayToByteString(thumbnailImage);
            }
            else
            {
                res.ThumbnailImage = ProtocolHelper.ByteArrayToByteString(new byte[0]);
            }

            log.Trace("(-)");
            return(res);
        }
        /// <summary>
        /// Creates a new instance of activity information from the activity.
        /// </summary>
        /// <returns>New instance of the ActivityInformation structure.</returns>
        public ActivityInformation ToActivityInformation()
        {
            GpsLocation         activityLocation = this.GetLocation();
            ActivityInformation res = new ActivityInformation()
            {
                Version              = new SemVer(this.Version).ToByteString(),
                Id                   = this.ActivityId,
                OwnerPublicKey       = ProtocolHelper.ByteArrayToByteString(this.OwnerPublicKey),
                ProfileServerContact = new ServerContactInfo()
                {
                    IpAddress   = ProtocolHelper.ByteArrayToByteString(this.OwnerProfileServerIpAddress),
                    NetworkId   = ProtocolHelper.ByteArrayToByteString(this.OwnerProfileServerId),
                    PrimaryPort = this.OwnerProfileServerPrimaryPort,
                },
                Type           = this.Type != null ? this.Type : "",
                Latitude       = activityLocation.GetLocationTypeLatitude(),
                Longitude      = activityLocation.GetLocationTypeLongitude(),
                Precision      = this.PrecisionRadius,
                StartTime      = ProtocolHelper.DateTimeToUnixTimestampMs(this.StartTime),
                ExpirationTime = ProtocolHelper.DateTimeToUnixTimestampMs(this.ExpirationTime),
                ExtraData      = this.ExtraData != null ? this.ExtraData : ""
            };

            return(res);
        }
        /// <summary>
        /// Creates SignedProfileInformation representation of the identity's profile.
        /// </summary>
        /// <returns>SignedProfileInformation structure describing the profile.</returns>
        public SignedProfileInformation ToSignedProfileInformation()
        {
            GpsLocation location         = this.GetInitialLocation();
            SignedProfileInformation res = new SignedProfileInformation()
            {
                Profile = new ProfileInformation()
                {
                    Version            = new SemVer(this.Version).ToByteString(),
                    PublicKey          = ProtocolHelper.ByteArrayToByteString(this.PublicKey),
                    Type               = this.Type,
                    Name               = this.Name,
                    ExtraData          = this.ExtraData,
                    Latitude           = location.GetLocationTypeLatitude(),
                    Longitude          = location.GetLocationTypeLongitude(),
                    ProfileImageHash   = ProtocolHelper.ByteArrayToByteString(this.ProfileImage != null ? this.ProfileImage : new byte[0]),
                    ThumbnailImageHash = ProtocolHelper.ByteArrayToByteString(this.ThumbnailImage != null ? this.ThumbnailImage: new byte[0])
                },
                Signature = ProtocolHelper.ByteArrayToByteString(this.Signature != null ? this.Signature : new byte[0])
            };

            return(res);
        }