private void Negotiate()
{
string lastName = string.Empty;
while (true)
{
string line = _pckIn.ReadString();
if (line.Length == 0)
{
if (_commonBase.Count == 0 || _multiAck)
{
_pckOut.WriteString("NAK\n");
}
_pckOut.Flush();
}
else if (line.StartsWith("have ") && line.Length == 45)
{
string name = line.Substring(5);
ObjectId id = ObjectId.FromString(name);
if (MatchHave(id))
{
if (_multiAck)
{
lastName = name;
_pckOut.WriteString("ACK " + name + " continue\n");
}
else if (_commonBase.Count == 1)
{
_pckOut.WriteString("ACK " + name + "\n");
}
}
else
{
if (_multiAck && OkToGiveUp())
{
_pckOut.WriteString("ACK " + name + " continue\n");
}
}
}
else if (line.Equals("done"))
{
if (_commonBase.Count == 0)
{
_pckOut.WriteString("NAK\n");
}
else if (_multiAck)
{
_pckOut.WriteString("ACK " + lastName + "\n");
}
break;
}
else
{
throw new PackProtocolException("expected have; got " + line);
}
}
}