Exemplo n.º 1
0
func HandleV2RevealEntry(state interfaces.IState, params interface{}) (interface{}, *primitives.JSONError) {
	e := new(EntryRequest)
	err := MapToObject(params, e)
	if err != nil {
		return nil, NewInvalidParamsError()
	}

	entry := entryBlock.NewEntry()
	if p, err := hex.DecodeString(e.Entry); err != nil {
		return nil, NewInvalidEntryError()
	} else {
		_, err := entry.UnmarshalBinaryData(p)
		if err != nil {
			return nil, NewInvalidEntryError()
		}
	}

	msg := new(messages.RevealEntryMsg)
	msg.Entry = entry
	msg.Timestamp = state.GetTimestamp()
	state.APIQueue() <- msg

	resp := new(RevealEntryResponse)
	resp.Message = "Entry Reveal Success"
	resp.EntryHash = entry.GetHash().String()

	return resp, nil
}
Exemplo n.º 2
0
func (m *MsgLog) PrtMsgs(state interfaces.IState) {
	m.sem.Lock()
	defer m.sem.Unlock()

	if len(m.MsgList) == 0 {
		return
	}

	fmt.Println(state.String())
	fmt.Println("\n-----------------------------------------------------")

	for _, e := range m.MsgList {
		if e.valid {

			dirstr := "->"
			if !e.out {
				dirstr = "<-"
			}

			fmt.Print(fmt.Sprintf("**** %8s %2s %8s %10s %5v     **** %s\n", e.name, dirstr, e.peer, e.where, e.valid, e.msg.String()))

		}
	}
	now := state.GetTimestamp()
	m.last = now
	m.msgCnt += len(m.MsgList) // Keep my counts
	m.msgCntp += len(m.MsgList)
	m.MsgList = m.MsgList[0:0] // Once printed, clear the list

	fmt.Println(fmt.Sprintf("*** %42s **** ", fmt.Sprintf("Length: %d    Msgs/sec: T %d P %d", len(m.MsgList), m.msgPerSec, m.msgPerSecp)))
	fmt.Println("\n-----------------------------------------------------")
}
Exemplo n.º 3
0
// Create a new Acknowledgement.  This Acknowledgement
func NewAck(state interfaces.IState, hash interfaces.IHash) (iack interfaces.IMsg, err error) {
	var last *Ack
	if state.GetLastAck() != nil {
		last = state.GetLastAck().(*Ack)
	}
	ack := new(Ack)
	ack.Timestamp = state.GetTimestamp()
	ack.MessageHash = hash
	if last == nil {
		ack.Height = 0
		ack.SerialHash = ack.MessageHash
	} else {
		ack.Height = last.Height + 1
		ack.SerialHash, err = primitives.CreateHash(last.MessageHash, ack.MessageHash)
		if err != nil {
			return nil, err
		}
	}

	state.SetLastAck(ack)

	// TODO:  Add the signature.

	return ack, nil
}
Exemplo n.º 4
0
func NewEntryBlockResponse(state interfaces.IState) interfaces.IMsg {
	msg := new(EntryBlockResponse)

	msg.Peer2Peer = true // Always a peer2peer request.
	msg.Timestamp = state.GetTimestamp()

	return msg
}
Exemplo n.º 5
0
func NewAddServerByHashMsg(state interfaces.IState, serverType int, newServerHash interfaces.IHash) interfaces.IMsg {
	msg := new(AddServerMsg)
	msg.ServerChainID = newServerHash
	msg.ServerType = serverType
	msg.Timestamp = state.GetTimestamp()

	return msg
}
Exemplo n.º 6
0
func NewAddServerMsg(state interfaces.IState, serverType int) interfaces.IMsg {
	msg := new(AddServerMsg)
	msg.ServerChainID = state.GetIdentityChainID()
	msg.ServerType = serverType
	msg.Timestamp = state.GetTimestamp()

	return msg

}
Exemplo n.º 7
0
func NewRemoveServerMsg(state interfaces.IState, chainId interfaces.IHash, serverType int) interfaces.IMsg {
	msg := new(RemoveServerMsg)
	msg.ServerChainID = chainId
	msg.ServerType = serverType
	msg.Timestamp = state.GetTimestamp()

	return msg

}
Exemplo n.º 8
0
func NewDBStateMissing(state interfaces.IState, dbheightStart uint32, dbheightEnd uint32) interfaces.IMsg {
	msg := new(DBStateMissing)

	msg.Peer2Peer = true // Always a peer2peer request.
	msg.Timestamp = state.GetTimestamp()
	msg.DBHeightStart = dbheightStart
	msg.DBHeightEnd = dbheightEnd

	return msg
}
Exemplo n.º 9
0
// Try and Resend.  Return true if we should keep the message, false if we should give up.
func (m *MessageBase) Expire(s interfaces.IState) (rtn bool) {
	now := s.GetTimestamp().GetTimeMilli()
	if m.expire == 0 {
		m.expire = now
	}
	if now-m.expire > 5*60*1000 { // Keep messages for some length before giving up.
		rtn = true
	}
	return
}
Exemplo n.º 10
0
func NewMissingData(state interfaces.IState, requestHash interfaces.IHash) interfaces.IMsg {

	msg := new(MissingData)

	msg.Peer2Peer = true // Always a peer2peer request.
	msg.Timestamp = state.GetTimestamp()
	msg.RequestHash = requestHash

	return msg
}
Exemplo n.º 11
0
func NewMissingMsgResponse(state interfaces.IState, msgResponse interfaces.IMsg, ackResponse interfaces.IMsg) interfaces.IMsg {

	msg := new(MissingMsgResponse)

	msg.Peer2Peer = true // Always a peer2peer request.
	msg.Timestamp = state.GetTimestamp()
	msg.MsgResponse = msgResponse
	msg.AckResponse = ackResponse

	return msg
}
Exemplo n.º 12
0
// Try and Resend.  Return true if we should keep the message, false if we should give up.
func (m *MessageBase) Resend(s interfaces.IState) (rtn bool) {
	now := s.GetTimestamp().GetTimeMilli()
	if m.resend == 0 {
		m.resend = now
		return false
	}
	if now-m.resend > 10000 && len(s.NetworkOutMsgQueue()) < 1000 { // Resend every second
		m.resend = now
		return true
	}
	return false
}
Exemplo n.º 13
0
func NewChangeServerKeyMsg(state interfaces.IState, identityChain interfaces.IHash, adminChange byte, keyPriority byte, keyType byte, key interfaces.IHash) interfaces.IMsg {
	msg := new(ChangeServerKeyMsg)
	msg.IdentityChainID = identityChain
	msg.AdminBlockChange = adminChange
	msg.KeyType = keyType
	msg.KeyPriority = keyPriority
	msg.Key = key
	msg.Timestamp = state.GetTimestamp()

	return msg

}
Exemplo n.º 14
0
// NewMissingMsg: Build a missing Message request, and add the first Height
func NewMissingMsg(state interfaces.IState, vm int, dbHeight uint32, processlistHeight uint32) *MissingMsg {

	msg := new(MissingMsg)

	msg.Asking = state.GetIdentityChainID()
	msg.Peer2Peer = true // Always a peer2peer request // .
	msg.VMIndex = vm
	msg.Timestamp = state.GetTimestamp()
	msg.DBHeight = dbHeight
	msg.ProcessListHeight = append(msg.ProcessListHeight, processlistHeight)
	msg.SystemHeight = uint32(state.GetSystemHeight(dbHeight))
	return msg
}
Exemplo n.º 15
0
func (m *FullServerFault) Priority(state interfaces.IState) (priority int64) {
	now := state.GetTimestamp()

	// After 20 seconds, a negotiation's priority is now zero.
	if now.GetTimeSeconds()-m.Timestamp.GetTimeSeconds() < 20 {
		return 0
	}

	// oldest timestamp is highest priority
	priority = math.MaxInt64 - m.Timestamp.GetTime().UnixNano()
	// Mask off lowest byte
	priority = (priority | 0xFF) ^ 0xFF
	// Add VMIndex
	priority = priority + int64(m.VMIndex)
	return
}
Exemplo n.º 16
0
func NewDataResponse(state interfaces.IState, dataObject interfaces.BinaryMarshallable,
	dataType int,
	dataHash interfaces.IHash) interfaces.IMsg {

	msg := new(DataResponse)

	msg.Peer2Peer = true
	msg.Timestamp = state.GetTimestamp()

	msg.DataHash = dataHash
	msg.DataType = dataType
	msg.DataObject = dataObject

	//fmt.Println("DATARESPONSE: ", msg.DataObject)

	return msg
}