Network resolution by total connection cost is working now.
Network resolution by total connection cost is working now.

--- a/.gitattributes
+++ b/.gitattributes
@@ -4,8 +4,8 @@
 # These files are text and should be normalized (convert crlf => lf)
 *.cs      text diff=csharp
 *.cfg     text
-*.csproj  text
-*.sln     text
+*.csproj  text eol=crlf
+*.sln     text eol=crlf
 
 # Images should be treated as binary
 # (binary is a macro for -text -diff)

--- a/ARConfiguration.cs
+++ b/ARConfiguration.cs
@@ -118,6 +118,10 @@
 			}
 		}
 
+		/// <summary>
+		/// Gets a value indicating whether we should use Toolbar if available.
+		/// </summary>
+		/// <value><c>true</c> if we should use Toolbar if available; otherwise, <c>false</c>.</value>
 		public static bool UseToolbarIfAvailable
 		{
 			get;

--- a/ARFlightController.cs
+++ b/ARFlightController.cs
@@ -317,8 +317,8 @@
 
 					log.AppendFormat("\n\tDoing target search for useful relay {0}", relay);
 
+					relay.FindNearestRelay();
 					relay.RecalculateTransmissionRates();
-					relay.FindNearestRelay();
 				}
 
 				// Very last, find routes for the non-best relays on the active vessel.

--- a/ARMapRenderer.cs
+++ b/ARMapRenderer.cs
@@ -322,6 +322,12 @@
 				while (enumerator.MoveNext())
 				{
 					lineRenderer = enumerator.Current;
+
+					if (lineRenderer == null)
+					{
+						continue;
+					}
+
 					lineRenderer.enabled = false;
 
 					if (freeObjects)

--- a/AntennaRange.csproj
+++ b/AntennaRange.csproj
@@ -80,6 +80,7 @@
     <Compile Include="ARConfiguration.cs" />
     <Compile Include="ARFlightController.cs" />
     <Compile Include="ARMapRenderer.cs" />
+    <Compile Include="RelayDataCost.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <ItemGroup>

--- a/AntennaRelay.cs
+++ b/AntennaRelay.cs
@@ -161,35 +161,50 @@
 		/// Gets the current link resource rate in EC/MiT.
 		/// </summary>
 		/// <value>The current link resource rate in EC/MiT.</value>
-		public virtual double CurrentLinkResourceRate
+		public virtual RelayDataCost CurrentLinkCost
 		{
 			get
 			{
-				return this.DataResourceCost;
-			}
-		}
-
-		public virtual double CurrentNetworkResourceRate
+				return new RelayDataCost(this.moduleRef.PacketResourceCost, this.moduleRef.PacketSize);
+			}
+		}
+
+		/// <summary>
+		/// Gets the current network link cost back to Kerbin, in EC/MiT.
+		/// </summary>
+		/// <value>The current network link cost back to Kerbin, in EC/MiT.</value>
+		public virtual RelayDataCost CurrentNetworkLinkCost
 		{
 			get
 			{
-				double totalRate = 0;
-
-				IAntennaRelay nextLink = this.moduleRef;
-
-				while (nextLink != null)
-				{
-					totalRate += nextLink.DataResourceCost;
-
-					if (nextLink.KerbinDirect)
+				RelayDataCost cost = new RelayDataCost();
+
+				IAntennaRelay relay = this.moduleRef;
+
+				ushort iters = 0;
+				while (relay != null)
+				{
+					cost += new RelayDataCost(relay.PacketResourceCost, relay.PacketSize);
+
+					if (relay.KerbinDirect)
 					{
 						break;
 					}
 
-					nextLink = nextLink.targetRelay;
-				}
-
-				return totalRate;
+					iters++;
+
+					if (iters > 255)
+					{
+						this.LogError("Bailing out of AntennaRelay.CurrentNetworkLinkCost because it looks like " +
+							"we're stuck in an infinite loop.  This is probably a bug.");
+						
+						break;
+					}
+
+					relay = relay.targetRelay;
+				}
+
+				return cost;
 			}
 		}
 
@@ -293,67 +308,86 @@
 			return this.canTransmit;
 		}
 
-		// Before transmission, set packetSize.  Per above, packet size increases with the inverse square of
-		// distance.  packetSize maxes out at _basepacketSize * maxDataFactor.
+		/// <summary>
+		/// Recalculates the transmission rates.
+		/// </summary>
 		public void RecalculateTransmissionRates()
 		{
-			float rangeFactor = (float)(this.NominalLinkSqrDistance / this.CurrentLinkSqrDistance);
+			if (!this.canTransmit) {
+				this.moduleRef.PacketSize = 0f;
+				this.moduleRef.PacketResourceCost = float.PositiveInfinity;
+				return;
+			}
+
+			RelayDataCost cost = this.GetPotentialLinkCost(this.CurrentLinkSqrDistance, this.NominalLinkSqrDistance);
+
+			this.moduleRef.PacketSize = cost.PacketSize;
+			this.moduleRef.PacketResourceCost = cost.PacketResourceCost;
+		}
+
+		/// <summary>
+		/// Gets the potential link cost, in EC/MiT.
+		/// </summary>
+		/// <returns>The potential link cost, in EC/MiT.</returns>
+		/// <param name="currentSqrDistance">Square of the current distance to the target</param>
+		/// <param name="nominalSqrDistance">Square of the nominal range to the target.</param>
+		public RelayDataCost GetPotentialLinkCost(double currentSqrDistance, double nominalSqrDistance)
+		{
+			RelayDataCost linkCost = new RelayDataCost();
+
+			float rangeFactor = (float)(nominalSqrDistance / currentSqrDistance);
+
+			linkCost.PacketSize = this.moduleRef.PacketSize;
 
 			if (ARConfiguration.FixedPowerCost)
 			{
-				this.moduleRef.PacketResourceCost = this.moduleRef.BasePacketResourceCost;
-
-				this.moduleRef.PacketSize = Mathf.Min(
+				linkCost.PacketResourceCost = this.moduleRef.BasePacketResourceCost;
+
+				linkCost.PacketSize = Mathf.Min(
 					this.moduleRef.BasePacketSize * rangeFactor,
 					this.moduleRef.BasePacketSize * this.moduleRef.MaxDataFactor
 				);
 			}
 			else
 			{
-				if (this.CurrentLinkSqrDistance > this.NominalLinkSqrDistance)
-				{
-					this.moduleRef.PacketSize = this.moduleRef.BasePacketSize;
-					this.moduleRef.PacketResourceCost = this.moduleRef.BasePacketResourceCost / rangeFactor;
+				if (currentSqrDistance > nominalSqrDistance)
+				{
+					linkCost.PacketSize = this.moduleRef.BasePacketSize;
+					linkCost.PacketResourceCost = this.moduleRef.BasePacketResourceCost / rangeFactor;
 				}
 				else
 				{
-					this.moduleRef.PacketSize = Mathf.Min(
+					linkCost.PacketSize = Mathf.Min(
 						this.moduleRef.BasePacketSize * rangeFactor,
 						this.moduleRef.BasePacketSize * this.moduleRef.MaxDataFactor
 					);
-					this.moduleRef.PacketResourceCost = this.moduleRef.BasePacketResourceCost;
-				}
-			}
-
-			this.moduleRef.PacketSize *= this.moduleRef.PacketThrottle / 100f;
-			this.moduleRef.PacketResourceCost *= this.moduleRef.PacketThrottle / 100f;
-		}
-
-		public double GetPotentialLinkCost(double currentSqrDistance, double nominalSqrDistance)
-		{
-			double cost;
-
-			float rangeFactor = (float)(nominalSqrDistance / currentSqrDistance);
-
-			if (ARConfiguration.FixedPowerCost || currentSqrDistance <= NominalLinkSqrDistance)
-			{
-				cost = this.moduleRef.BasePacketResourceCost;
-			}
-			else
-			{
-				cost = this.moduleRef.BasePacketResourceCost / rangeFactor;
-			}
-
-			cost *= this.moduleRef.PacketThrottle / 100f;
-
-			return cost;
-		}
-
-		public double GetPotentialLinkCost(IAntennaRelay potentialTarget)
+					linkCost.PacketResourceCost = this.moduleRef.BasePacketResourceCost;
+				}
+			}
+
+			linkCost.PacketResourceCost *= this.moduleRef.PacketThrottle / 100f;
+			linkCost.PacketSize *= this.moduleRef.PacketThrottle / 100f;
+
+			return linkCost;
+		}
+
+		/// <summary>
+		/// Gets the potential link cost, in EC/MiT.
+		/// </summary>
+		/// <returns>The potential link cost, in EC/MiT.</returns>
+		/// <param name="potentialTarget">Potential target relay.</param>
+		public RelayDataCost GetPotentialLinkCost(IAntennaRelay potentialTarget)
 		{
 			if (potentialTarget == null)
 			{
-				return double.PositiveInfinity;
+				return RelayDataCost.Infinity;
+			}
+
+			double currentSqrDistance = this.SqrDistanceTo(potentialTarget);
+
+			if (currentSqrDistance > this.MaxLinkSqrDistanceTo(potentialTarget))
+			{
+				return RelayDataCost.Infinity;
 			}
 
 			double nominalSqrDistance;
@@ -366,16 +400,26 @@
 				nominalSqrDistance = this.nominalTransmitDistance * this.nominalTransmitDistance;
 			}
 
-			double currentSqrDistance = this.SqrDistanceTo(potentialTarget);
-
 			return GetPotentialLinkCost(currentSqrDistance, nominalSqrDistance);
 		}
 
-		public double GetPotentialLinkCost(CelestialBody body)
+		/// <summary>
+		/// Gets the potential link cost, in EC/MiT.
+		/// </summary>
+		/// <returns>The potential link cost, in EC/MiT.</returns>
+		/// <param name="body">Potential target Body</param>
+		public RelayDataCost GetPotentialLinkCost(CelestialBody body)
 		{
 			if (body == null || body != Kerbin)
 			{
-				return double.PositiveInfinity;
+				return RelayDataCost.Infinity;
+			}
+
+			double currentSqrDistance = this.SqrDistanceTo(body);
+
+			if (currentSqrDistance > this.MaxLinkSqrDistanceTo(body))
+			{
+				return RelayDataCost.Infinity;
 			}
 
 			double nominalSqrDistance;
@@ -387,8 +431,6 @@
 			{
 				nominalSqrDistance = this.nominalTransmitDistance * this.nominalTransmitDistance;
 			}
-
-			double currentSqrDistance = this.SqrDistanceTo(body);
 
 			return GetPotentialLinkCost(currentSqrDistance, nominalSqrDistance);
 		}
@@ -442,12 +484,12 @@
 			CelestialBody bodyOccludingBestOccludedRelay = null;
 			IAntennaRelay needle;
 
-			double cheapestRelayRate = double.PositiveInfinity;
-			double cheapestOccludedRelayRate = double.PositiveInfinity;
-
-			double potentialRelayRate;
-
-			double kerbinRelayRate = this.GetPotentialLinkCost(Kerbin);
+			RelayDataCost cheapestRelayRate = RelayDataCost.Infinity;
+			RelayDataCost cheapestOccludedRelayRate = RelayDataCost.Infinity;
+
+			RelayDataCost potentialRelayRate;
+
+			RelayDataCost kerbinRelayRate = this.GetPotentialLinkCost(Kerbin);
 
 			bool isCircular;
 			int iterCount;
@@ -503,7 +545,9 @@
 
 				// Find the distance from here to the vessel...
 				log.Append("\n\tgetting cost to potential vessel");
-				potentialRelayRate = potentialBestRelay.CurrentNetworkResourceRate + this.GetPotentialLinkCost(potentialBestRelay);
+				potentialRelayRate = potentialBestRelay.CurrentNetworkLinkCost + this.GetPotentialLinkCost(potentialBestRelay);
+
+				log.AppendFormat("\n\tpotentialRelayRate = {0} ({1} + {2})", potentialRelayRate, potentialBestRelay.CurrentNetworkLinkCost, this.GetPotentialLinkCost(potentialBestRelay));
 
 				#if BENCH
 				startLOSVesselTicks = performanceTimer.ElapsedTicks;
@@ -575,9 +619,13 @@
 				if (potentialRelayRate > cheapestRelayRate)
 				{
 					
-					log.AppendFormat("\n\t{0}: Relay {1} discarded because it is more expensive than another the nearest relay.",
+					log.AppendFormat(
+							"\n\t{0}: Relay {1} discarded because it is more expensive than the cheapest relay." +
+							"\n\t\t({2}, {3} > {4})",
 						this.ToString(),
-						potentialBestRelay
+						potentialBestRelay,
+						this.nearestRelay == null ? "NULL" : this.nearestRelay.ToString(),
+						potentialRelayRate, cheapestRelayRate
 					);
 					continue;
 				}
@@ -647,7 +695,7 @@
 						log.AppendFormat("\n\t{0}: found new cheapest relay {1} ({2} EC/MiT)",
 							this.ToString(),
 							this.nearestRelay.ToString(),
-							Math.Sqrt(cheapestRelayRate)
+							cheapestRelayRate
 						);
 					}
 					else
@@ -678,7 +726,7 @@
 
 			log.AppendFormat("\n{0} ({1}): Search done, figuring status.", this.ToString(), this.GetType().Name);
 			log.AppendFormat(
-				"\n{0}: nearestRelay={1} ({2})), bestOccludedRelay={3} ({4}), kerbinSqrDistance={5}m²)",
+					"\n{0}: nearestRelay={1} ({2})), bestOccludedRelay={3} ({4}), kerbinRelayRate={5} EC/MiT)",
 				this,
 				this.nearestRelay == null ? "null" : this.nearestRelay.ToString(),
 				cheapestRelayRate,
@@ -1046,6 +1094,7 @@
 		/// as an <see cref="AntennaRange.IAntennaRelay"/></param>
 		public AntennaRelay(IAntennaRelay module)
 		{
+			this.KerbinDirect = true;
 			this.moduleRef = module;
 
 			#if BENCH

--- a/IAntennaRelay.cs
+++ b/IAntennaRelay.cs
@@ -46,16 +46,40 @@
 		/// </summary>
 		IAntennaRelay targetRelay { get; }
 
+		/// <summary>
+		/// Gets or sets the data capacity of a packet, in MiT/packet
+		/// </summary>
+		/// <value>The data capacity of a packet, in MiT/packet</value>
 		float PacketSize { get; set; }
 
+		/// <summary>
+		/// Gets the base data capacity of a packet, in MiT/packet
+		/// </summary>
+		/// <value>The base data capacity of a packet, in MiT/packet</value>
 		float BasePacketSize { get; }
 
+		/// <summary>
+		/// Gets or sets the resource cost of a packet, in EC/packet
+		/// </summary>
+		/// <value>The resource cost of a packet, in EC/packet</value>
 		float PacketResourceCost { get; set; }
 
+		/// <summary>
+		/// Gets the base resource cost of a packet, in EC/packet
+		/// </summary>
+		/// <value>The base resource cost of a packet, in EC/packet</value>
 		float BasePacketResourceCost { get; }
 
+		/// <summary>
+		/// Gets the packet throttle.
+		/// </summary>
+		/// <value>The packet throttle in range [0..100].</value>
 		float PacketThrottle { get; }
 
+		/// <summary>
+		/// Gets the max data factor.
+		/// </summary>
+		/// <value>The max data factor.</value>
 		float MaxDataFactor { get; }
 
 		/// <summary>
@@ -68,7 +92,7 @@
 		/// Gets the current network resource rate in EC/MiT.
 		/// </summary>
 		/// <value>The current network resource rate in EC/MiT.</value>
-		double CurrentNetworkResourceRate { get; }
+		RelayDataCost CurrentNetworkLinkCost { get; }
 
 		/// <summary>
 		/// Gets a value indicating whether this <see cref="AntennaRange.IAntennaRelay"/> Relay is communicating

--- a/ModuleLimitedDataTransmitter.cs
+++ b/ModuleLimitedDataTransmitter.cs
@@ -186,6 +186,10 @@
 			}
 		}
 
+		/// <summary>
+		/// Gets or sets the data capacity of a packet, in MiT/packet
+		/// </summary>
+		/// <value>The data capacity of a packet, in MiT/packet</value>
 		public float PacketSize
 		{
 			get
@@ -198,12 +202,20 @@
 			}
 		}
 
+		/// <summary>
+		/// Gets the base data capacity of a packet, in MiT/packet
+		/// </summary>
+		/// <value>The base data capacity of a packet, in MiT/packet</value>
 		public float BasePacketSize
 		{
 			get;
 			private set;
 		}
 
+		/// <summary>
+		/// Gets or sets the resource cost of a packet, in EC/packet
+		/// </summary>
+		/// <value>The resource cost of a packet, in EC/packet</value>
 		public float PacketResourceCost
 		{
 			get
@@ -216,12 +228,20 @@
 			}
 		}
 
+		/// <summary>
+		/// Gets the base resource cost of a packet, in EC/packet
+		/// </summary>
+		/// <value>The base resource cost of a packet, in EC/packet</value>
 		public float BasePacketResourceCost
 		{
 			get;
 			private set;
 		}
 
+		/// <summary>
+		/// Gets the packet throttle.
+		/// </summary>
+		/// <value>The packet throttle in range [0..100].</value>
 		public float PacketThrottle
 		{
 			get
@@ -230,6 +250,10 @@
 			}
 		}
 
+		/// <summary>
+		/// Gets the max data factor.
+		/// </summary>
+		/// <value>The max data factor.</value>
 		public float MaxDataFactor
 		{
 			get
@@ -316,23 +340,6 @@
 				}
 
 				return this.relay.CurrentLinkSqrDistance;
-			}
-		}
-
-		/// <summary>
-		/// Gets the current link resource rate in EC/MiT.
-		/// </summary>
-		/// <value>The current link resource rate in EC/MiT.</value>
-		public double CurrentLinkResourceRate
-		{
-			get
-			{
-				if (this.relay == null)
-				{
-					return double.PositiveInfinity;
-				}
-
-				return this.relay.CurrentLinkResourceRate;
 			}
 		}
 
@@ -450,16 +457,20 @@
 			}
 		}
 
-		public double CurrentNetworkResourceRate
+		/// <summary>
+		/// Gets the current network resource rate in EC/MiT.
+		/// </summary>
+		/// <value>The current network resource rate in EC/MiT.</value>
+		public RelayDataCost CurrentNetworkLinkCost
 		{
 			get
 			{
 				if (this.relay == null)
 				{
-					return double.PositiveInfinity;
-				}
-
-				return this.relay.CurrentNetworkResourceRate;
+					return RelayDataCost.Infinity;
+				}
+
+				return this.relay.CurrentNetworkLinkCost;
 			}
 		}
 
@@ -691,6 +702,9 @@
 			return this.relay.CanTransmit();
 		}
 
+		/// <summary>
+		/// Recalculates the transmission rates.
+		/// </summary>
 		public void RecalculateTransmissionRates()
 		{
 			if (this.relay != null)
@@ -902,6 +916,9 @@
 			}
 		}
 
+		/// <summary>
+		/// Recalculates the max range; useful for making sure we're using additive ranges when enabled.
+		/// </summary>
 		public void RecalculateMaxRange()
 		{
 			this.maxTransmitDistance = Math.Sqrt(this.maxPowerFactor) * this.nominalTransmitDistance;

--- a/Properties/AssemblyInfo.cs
+++ b/Properties/AssemblyInfo.cs

--- a/ProtoAntennaRelay.cs
+++ b/ProtoAntennaRelay.cs
@@ -72,6 +72,10 @@
 			}
 		}
 
+		/// <summary>
+		/// Gets or sets the data capacity of a packet, in MiT/packet
+		/// </summary>
+		/// <value>The data capacity of a packet, in MiT/packet</value>
 		public float PacketSize
 		{
 			get
@@ -94,6 +98,10 @@
 			}
 		}
 
+		/// <summary>
+		/// Gets the base data capacity of a packet, in MiT/packet
+		/// </summary>
+		/// <value>The base data capacity of a packet, in MiT/packet</value>
 		public float BasePacketSize
 		{
 			get
@@ -107,6 +115,10 @@
 			}
 		}
 
+		/// <summary>
+		/// Gets or sets the resource cost of a packet, in EC/packet
+		/// </summary>
+		/// <value>The resource cost of a packet, in EC/packet</value>
 		public float PacketResourceCost
 		{
 			get
@@ -129,6 +141,10 @@
 			}
 		}
 
+		/// <summary>
+		/// Gets the base resource cost of a packet, in EC/packet
+		/// </summary>
+		/// <value>The base resource cost of a packet, in EC/packet</value>
 		public float BasePacketResourceCost
 		{
 			get
@@ -142,6 +158,10 @@
 			}
 		}
 
+		/// <summary>
+		/// Gets the packet throttle.
+		/// </summary>
+		/// <value>The packet throttle in range [0..100].</value>
 		public float PacketThrottle
 		{
 			get
@@ -155,6 +175,10 @@
 			}
 		}
 
+		/// <summary>
+		/// Gets the max data factor.
+		/// </summary>
+		/// <value>The max data factor.</value>
 		public float MaxDataFactor
 		{
 			get
@@ -228,6 +252,9 @@
 			return base.CanTransmit();
 		}
 
+		/// <summary>
+		/// Recalculates the max range; useful for making sure we're using additive ranges when enabled.
+		/// </summary>
 		public void RecalculateMaxRange()
 		{
 			if (this.moduleRef != null)

file:b/RelayDataCost.cs (new)
--- /dev/null
+++ b/RelayDataCost.cs
@@ -1,1 +1,259 @@
-
+// AntennaRange
+//
+// RelayLinkCost.cs
+//
+// Copyright © 2016, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+//    this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation and/or other
+//    materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+//    to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+using System;
+using UnityEngine;
+
+namespace AntennaRange
+{
+	/// <summary>
+	/// A struct representing the cost of sending data through a relay.
+	/// </summary>
+	public struct RelayDataCost : IComparable, IComparable<RelayDataCost>
+	{
+		/// <summary>
+		/// A RelayDataCost object representing infinitely high cost.
+		/// </summary>
+		public static readonly RelayDataCost Infinity = new RelayDataCost(float.PositiveInfinity, 0f);
+
+		/// <param name="one">Left</param>
+		/// <param name="two">Right</param>
+		public static RelayDataCost operator+ (RelayDataCost one, RelayDataCost two)
+		{
+			RelayDataCost gcd, lcd;
+
+			if (one.PacketSize > two.PacketSize) {
+				gcd = one;
+				lcd = two;
+			}
+			else
+			{
+				gcd = two;
+				lcd = one;
+			}
+
+			if (lcd.PacketSize != 0f)
+			{
+				float mul = gcd.PacketSize / lcd.PacketSize;
+
+				lcd.PacketSize *= mul;
+				lcd.PacketResourceCost *= mul;
+			}
+
+			return new RelayDataCost(gcd.PacketResourceCost + lcd.PacketResourceCost, gcd.PacketSize + lcd.PacketSize);
+		}
+
+		/// <param name="only">RelayDataCost to be negated</param>
+		public static RelayDataCost operator- (RelayDataCost only)
+		{
+			return new RelayDataCost(-only.PacketResourceCost, only.PacketSize);
+		}
+
+		/// <param name="left">Left.</param>
+		/// <param name="right">Right.</param>
+		public static RelayDataCost operator- (RelayDataCost left, RelayDataCost right)
+		{
+			return left + -right;
+		}
+
+		/// <param name="left">Left.</param>
+		/// <param name="right">Right.</param>
+		public static bool operator> (RelayDataCost left, RelayDataCost right)
+		{
+			return (left.CompareTo(right) > 0);
+		}
+
+		/// <param name="left">Left.</param>
+		/// <param name="right">Right.</param>
+		public static bool operator>= (RelayDataCost left, RelayDataCost right)
+		{
+			return (left.CompareTo(right) >= 0);
+		}
+
+		/// <param name="left">Left.</param>
+		/// <param name="right">Right.</param>
+		public static bool operator== (RelayDataCost left, RelayDataCost right)
+		{
+			return (left.CompareTo(right) == 0);
+		}
+
+		/// <param name="left">Left.</param>
+		/// <param name="right">Right.</param>
+		public static bool operator<= (RelayDataCost left, RelayDataCost right)
+		{
+			return (left.CompareTo(right) <= 0);
+		}
+
+		/// <param name="left">Left.</param>
+		/// <param name="right">Right.</param>
+		public static bool operator< (RelayDataCost left, RelayDataCost right)
+		{
+			return (left.CompareTo(right) < 0);
+		}
+
+		/// <param name="left">Left.</param>
+		/// <param name="right">Right.</param>
+		public static bool operator!= (RelayDataCost left, RelayDataCost right)
+		{
+			return (left.CompareTo(right) != 0);
+		}
+
+		/// <summary>
+		/// The resource cost of a packet, in EC/packet
+		/// </summary>
+		public float PacketResourceCost;
+
+		/// <summary>
+		/// The data capacity of a packet, MiT/packet
+		/// </summary>
+		public float PacketSize;
+
+		/// <summary>
+		/// Gets the resource cost per unit data, in EC/MiT
+		/// </summary>
+		/// <value>The resource cost per unit data, in EC/MiT</value>
+		public double ResourceCostPerData
+		{
+			get
+			{
+				if (this.PacketSize == 0f || float.IsInfinity(this.PacketResourceCost))
+				{
+					return double.PositiveInfinity;
+				}
+
+				return (double)this.PacketResourceCost / (double)this.PacketSize;
+			}
+		}
+
+		/// <summary>
+		/// Initializes a new instance of the <see cref="AntennaRange.RelayDataCost"/> struct.
+		/// </summary>
+		/// <param name="cost">resource cost of a packet, in EC/packet</param>
+		/// <param name="size">data capacity of a packet, MiT/packet</param>
+		public RelayDataCost(float cost, float size)
+		{
+			this.PacketResourceCost = cost;
+			this.PacketSize = size;
+		}
+
+		/// <summary>
+		/// Returns a <see cref="System.String"/> that represents the current <see cref="AntennaRange.RelayDataCost"/>.
+		/// </summary>
+		/// <returns>A <see cref="System.String"/> that represents the current <see cref="AntennaRange.RelayDataCost"/>.</returns>
+		public override string ToString()
+		{
+			return string.Format("{0} EC/MiT", this.ResourceCostPerData);
+		}
+
+		/// <summary>
+		/// Determines whether the specified <see cref="System.Object"/> is equal to the current <see cref="AntennaRange.RelayDataCost"/>.
+		/// </summary>
+		/// <param name="obj">The <see cref="System.Object"/> to compare with the current <see cref="AntennaRange.RelayDataCost"/>.</param>
+		/// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to the current
+		/// <see cref="AntennaRange.RelayDataCost"/>; otherwise, <c>false</c>.</returns>
+		public override bool Equals(object obj)
+		{
+			if (obj is RelayDataCost)
+			{
+				return ((RelayDataCost)obj == this);
+			}
+			else
+			{
+				return false;
+			}
+		}
+
+		/// <summary>
+		/// Serves as a hash function for a <see cref="AntennaRange.RelayDataCost"/> object.
+		/// </summary>
+		/// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a hash table.</returns>
+		public override int GetHashCode()
+		{
+			int hash = 137;
+
+			hash = (hash * 61) + this.PacketResourceCost.GetHashCode();
+			hash = (hash * 61) + this.PacketSize.GetHashCode();
+
+			return hash;
+		}
+
+		/// <summary>
+		/// Compares this RelayDataCost to another object.  Throws NotImplementedException for objects
+		/// that are not RelayDataCost objects
+		/// </summary>
+		/// <returns>-1 if this is less than o, 0 if this equals o, 1 if this is greater than o</returns>
+		/// <param name="o">Another object</param>
+		public int CompareTo(object o)
+		{
+			if (o is RelayDataCost)
+			{
+				return this.CompareTo((RelayDataCost)o);
+			}
+
+			throw new NotImplementedException(
+				string.Format(
+					"Cannot compare {0} to foreign type {1}",
+					this.GetType().Name,
+					o.GetType().Name
+				)
+			);
+		}
+
+		/// <summary>
+		/// Compares this RelayDataCost to another object.  Throws NotImplementedException for objects
+		/// that are not RelayDataCost objects
+		/// </summary>
+		/// <returns>-1 if this is less than o, 0 if this equals o, 1 if this is greater than o</returns>
+		/// <param name="o">Another RelayDataCost</param>
+		public int CompareTo(RelayDataCost o)
+		{
+			int val;
+
+			if (this.ResourceCostPerData > o.ResourceCostPerData)
+			{
+				val = 1;
+			}
+			else if (this.ResourceCostPerData < o.ResourceCostPerData)
+			{
+				val = -1;
+			}
+			else
+			{
+				val = 0;
+			}
+
+			#if DEBUG
+			Debug.LogErrorFormat("RelayLinkCost comparing {0} to {1}, returning {2}", this, o, val);
+			#endif
+
+			return val;
+		}
+	}
+}
+
+

--- a/RelayDatabase.cs
+++ b/RelayDatabase.cs

--- a/RelayExtensions.cs
+++ b/RelayExtensions.cs
@@ -143,6 +143,12 @@
 			return relayOne.vessel.sqrDistanceTo(relayTwo.vessel);
 		}
 
+		/// <summary>
+		/// Returns the square of the maximum link range between two relays.
+		/// </summary>
+		/// <returns>The maximum link range between two relays.</returns>
+		/// <param name="relayOne">Relay one.</param>
+		/// <param name="relayTwo">Relay two.</param>
 		public static double MaxLinkSqrDistanceTo(this AntennaRelay relayOne, IAntennaRelay relayTwo)
 		{
 			if (ARConfiguration.UseAdditiveRanges)
@@ -155,6 +161,12 @@
 			}
 		}
 
+		/// <summary>
+		/// Returns the square of the maximum link range between a relay and Kerbin.
+		/// </summary>
+		/// <returns>The maximum link range between a relay and Kerbin.</returns>
+		/// <param name="relayOne">Relay one.</param>
+		/// <param name="body">A CelestialBody (must be Kerbin).</param>
 		public static double MaxLinkSqrDistanceTo(this AntennaRelay relayOne, CelestialBody body)
 		{
 			if (body != AntennaRelay.Kerbin)
@@ -172,6 +184,12 @@
 			}
 		}
 
+		/// <summary>
+		/// Determines if relayOne is in range of the specified relayTwo.
+		/// </summary>
+		/// <returns><c>true</c> if relayOne is in range of the specifie relayTwo; otherwise, <c>false</c>.</returns>
+		/// <param name="relayOne">Relay one.</param>
+		/// <param name="relayTwo">Relay two.</param>
 		public static bool IsInRangeOf(this AntennaRelay relayOne, IAntennaRelay relayTwo)
 		{
 			if (relayOne == null || relayTwo == null)
@@ -182,7 +200,12 @@
 			return relayOne.SqrDistanceTo(relayTwo) <= relayOne.MaxLinkSqrDistanceTo(relayTwo);
 		}
 
-
+		/// <summary>
+		/// Determines if relayOne is in range of the specified body.
+		/// </summary>
+		/// <returns><c>true</c> if relayOne is in range of the specified body; otherwise, <c>false</c>.</returns>
+		/// <param name="relayOne">Relay one.</param>
+		/// <param name="body">Body.</param>
 		public static bool IsInRangeOf(this AntennaRelay relayOne, CelestialBody body)
 		{
 			if (relayOne == null || body == null)