Exemplo n.º 1
0
// Get remote hashed intervals
func netDstReceiver(decoder *gob.Decoder, netInStream chan<- HashedInterval, netInStreamDone chan<- bool) {
	status := true
	for {
		if verboseClient {
			log.Debug("Client.netDstReceiver decoding...")
		}
		var r HashedInterval
		err := decoder.Decode(&r)
		if err != nil {
			log.Fatal("Cient protocol error:", err)
			status = false
			break
		}
		// interval := r.Interval
		if r.Kind == SparseIgnore {
			if verboseClient {
				log.Debug("Client.netDstReceiver got <eof>")
			}
			break
		}
		if verboseClient {
			switch r.Kind {
			case SparseData:
				log.Debug("Client.netDstReceiver got data", r.FileInterval, "hash[", len(r.Hash), "]")
			case SparseHole:
				log.Debug("Client.netDstReceiver got hole", r.FileInterval)
			}
		}
		netInStream <- r
	}
	close(netInStream)
	netInStreamDone <- status
}
Exemplo n.º 2
0
func meta(cfg HiveConfig) hiveMeta {
	m := hiveMeta{}

	var dec *gob.Decoder
	metapath := path.Join(cfg.StatePath, "meta")
	f, err := os.Open(metapath)
	if err != nil {
		// TODO(soheil): We should also update our peer addresses when we have an
		// existing meta.
		m.Peers = peersInfo(cfg.PeerAddrs)
		m.Hive.Addr = cfg.Addr
		if len(cfg.PeerAddrs) == 0 {
			// The initial ID is 1. There is no raft node up yet to allocate an ID. So
			// we must do this when the hive starts.
			m.Hive.ID = 1
			goto save
		}

		m.Hive.ID = hiveIDFromPeers(cfg.Addr, cfg.PeerAddrs)
		goto save
	}

	dec = gob.NewDecoder(f)
	if err = dec.Decode(&m); err != nil {
		glog.Fatalf("Cannot decode meta: %v", err)
	}
	m.Hive.Addr = cfg.Addr
	f.Close()

save:
	saveMeta(m, cfg)
	return m
}
Exemplo n.º 3
0
func sendSyncRequest(encoder *gob.Encoder, decoder *gob.Decoder, path string, size int64, salt []byte) bool {
	err := encoder.Encode(requestHeader{requestMagic, syncRequestCode})
	if err != nil {
		log.Fatal("Client protocol encoder error:", err)
		return false
	}
	err = encoder.Encode(path)
	if err != nil {
		log.Fatal("Client protocol encoder error:", err)
		return false
	}
	err = encoder.Encode(size)
	if err != nil {
		log.Fatal("Client protocol encoder error:", err)
		return false
	}
	err = encoder.Encode(salt)
	if err != nil {
		log.Fatal("Client protocol encoder error:", err)
		return false
	}

	var ack bool
	err = decoder.Decode(&ack)
	if err != nil {
		log.Fatal("Client protocol decoder error:", err)
		return false
	}

	return ack
}
Exemplo n.º 4
0
func (p *IndexDb) LoadIndexConfig(path string) (*IndexDbConfig, error) {
	// initialize a buffer object
	var buf bytes.Buffer

	// initialize gob decoder
	var dec *gob.Decoder = gob.NewDecoder(&buf)

	// open the config file
	file, err := os.Open(path)
	if err != nil {
		return nil, err
		// log.Fatal(err)
	}

	// decode from the content of the file.
	_, err = buf.ReadFrom(file)
	if err != nil {
		return nil, err
		// log.Fatal(err)
	}

	var config IndexDbConfig
	err = dec.Decode(&config)
	if err != nil {
		return nil, err
		// log.Fatal("decode error:", decodeErr)
	}
	return &config, err
}
Exemplo n.º 5
0
func (m *Manager) handleRequest(decoder *gob.Decoder,
	messageChan chan<- *proto.ServerMessage) error {
	var request proto.ClientRequest
	if err := decoder.Decode(&request); err != nil {
		if err == io.EOF {
			return err
		}
		return errors.New("error decoding ClientRequest: " + err.Error())
	}
	serverMessage := new(proto.ServerMessage)
	if request := request.YieldRequest; request != nil {
		m.updateMachineData(request.Machine)
		fileInfos := make([]proto.FileInfo, len(request.Pathnames))
		serverMessage.YieldResponse = &proto.YieldResponse{
			Hostname: request.Machine.Hostname,
			Files:    fileInfos}
		for index, pathname := range request.Pathnames {
			fileInfos[index] = m.computeFile(request.Machine, pathname)
		}
	}
	if request := request.GetObjectRequest; request != nil {
		_, reader, err := m.objectServer.GetObject(request.Hash)
		if err != nil {
			return err
		} else {
			data, _ := ioutil.ReadAll(reader)
			serverMessage.GetObjectResponse = &proto.GetObjectResponse{
				Hash: request.Hash,
				Data: data}
			reader.Close()
		}
	}
	messageChan <- serverMessage
	return nil
}
Exemplo n.º 6
0
func (conn *LocalConnection) exchangeHandshake(localConnID uint64, usingPassword bool, enc *gob.Encoder, dec *gob.Decoder) (*FieldValidator, *[32]byte, error) {
	handshakeSend := map[string]string{
		"PeerNameFlavour": PeerNameFlavour,
		"Name":            conn.local.Name.String(),
		"NickName":        conn.local.NickName,
		"UID":             fmt.Sprint(conn.local.UID),
		"ConnID":          fmt.Sprint(localConnID)}
	handshakeRecv := map[string]string{}
	var public, private *[32]byte
	var err error
	if usingPassword {
		public, private, err = GenerateKeyPair()
		if err != nil {
			return nil, nil, err
		}
		handshakeSend["PublicKey"] = hex.EncodeToString(public[:])
	}
	enc.Encode(handshakeSend)
	if err = dec.Decode(&handshakeRecv); err != nil {
		return nil, nil, err
	}
	fv := NewFieldValidator(handshakeRecv)
	fv.CheckEqual("PeerNameFlavour", PeerNameFlavour)
	return fv, private, nil
}
Exemplo n.º 7
0
func (s *Server) clientReadRoutine(dec *gob.Decoder) {
	defer s.StackCatcher()
	for {
		var data wireData
		err := dec.Decode(&data)
		if err != nil {
			if s.Logger != nil {
				s.Logger.Printf("CGF client read error: %v", err)
			}
			panic(err)
			return
		}
		switch {
		case data.GetErr() != nil:
			if s.Logger != nil {
				s.Logger.Printf("CGF error from server: %v", data.GetErr())
			}
			return

		case data.CompleteBundle != nil:
			s.Complete_bundles <- *data.CompleteBundle

		case data.Setup != nil:
			// Rawr?
		}
	}
}
Exemplo n.º 8
0
func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder) {
	usingPassword := conn.SessionKey != nil
	var receiver TCPReceiver
	if usingPassword {
		receiver = NewEncryptedTCPReceiver(conn.SessionKey, conn.outbound)
	} else {
		receiver = NewSimpleTCPReceiver()
	}
	var err error
	for {
		var msg []byte
		conn.extendReadDeadline()
		if err = decoder.Decode(&msg); err != nil {
			break
		}
		msg, err = receiver.Decode(msg)
		if err != nil {
			break
		}
		if len(msg) < 1 {
			conn.Log("ignoring blank msg")
			continue
		}
		if err = conn.handleProtocolMsg(ProtocolTag(msg[0]), msg[1:]); err != nil {
			break
		}
	}
	conn.Shutdown(err)
}
Exemplo n.º 9
0
func (proto *latencyProtocol) decodeMeasureLatency(dec *gob.Decoder) (interface{}, error) {
	var val MeasureLatency
	err := dec.Decode(&val)
	if err != nil {
		return nil, fmt.Errorf("Error decoding MeasureLatency value: %v", err)
	}
	return &val, nil
}
Exemplo n.º 10
0
func (proto *heartbeatProtocol) decodeConfigureHeartbeat(decoder *gob.Decoder) (interface{}, error) {
	var val ConfigureHeartbeatPacket
	err := decoder.Decode(&val)
	if err != nil {
		return nil, fmt.Errorf("Error decoding ConfigureHeartbeat value: %v", err)
	}
	return &val, nil
}
Exemplo n.º 11
0
func (proto *loadProtocol) decodeLoad(decoder *gob.Decoder) (interface{}, error) {
	var val LoadPacket
	err := decoder.Decode(&val)
	if err != nil {
		return nil, fmt.Errorf("Error decoding LoadPacket value: %v", err)
	}
	return &val, nil
}
Exemplo n.º 12
0
func (proto *pcpProtocol) decodeStopProxy(decoder *gob.Decoder) (interface{}, error) {
	var val StopProxy
	err := decoder.Decode(&val)
	if err != nil {
		return nil, fmt.Errorf("Error decoding PCP StopProxy value: %v", err)
	}
	return &val, nil
}
Exemplo n.º 13
0
func (frag *defaultProtocolFragment) decodeError(decoder *gob.Decoder) (interface{}, error) {
	var val string
	err := decoder.Decode(&val)
	if err != nil {
		return nil, fmt.Errorf("Error decoding Error value: %v", err)
	}
	return val, nil
}
Exemplo n.º 14
0
func receiveIncoming(dec *gob.Decoder, channel chan map[string]control.ElevatorNode) {
	var newMap = make(map[string]control.ElevatorNode)
	for {
		dec.Decode(&newMap)
		//fmt.Println(newMap)
		channel <- newMap
	}
}
Exemplo n.º 15
0
func (proto *ampControlProtocol) decodeResumeStream(decoder *gob.Decoder) (interface{}, error) {
	var val ResumeStream
	err := decoder.Decode(&val)
	if err != nil {
		return nil, fmt.Errorf("Error decoding AMPcontrol ResumeStream value: %v", err)
	}
	return &val, nil
}
Exemplo n.º 16
0
func (proto *pingProtocol) decodePong(decoder *gob.Decoder) (interface{}, error) {
	var val PongPacket
	err := decoder.Decode(&val)
	if err != nil {
		return nil, fmt.Errorf("Error decoding Pong value: %v", err)
	}
	return &val, nil
}
Exemplo n.º 17
0
func decodePeer(dec *gob.Decoder) (peerSummary PeerSummary, connSummaries []ConnectionSummary, err error) {
	if err = dec.Decode(&peerSummary); err != nil {
		return
	}
	if err = dec.Decode(&connSummaries); err != nil {
		return
	}
	return
}
Exemplo n.º 18
0
func (cbv *CachedBackendVersion) decodeCacheFromGob(dec *gob.Decoder) error {
	cbv.mu.Lock()
	defer cbv.mu.Unlock()

	if err := dec.Decode(&cbv.cache); err != nil {
		return fmt.Errorf("Failed to decode cache map: %v", err)
	}
	return nil
}
Exemplo n.º 19
0
func (tb *TableBlock) unpackSetCol(dec *gob.Decoder, info SavedColumnInfo) {
	records := tb.RecordList

	saved_col := NewSavedSetColumn()
	into := &saved_col
	err := dec.Decode(into)
	if err != nil {
		log.Println("DECODE COL ERR:", err)
	}

	col_id := tb.table.get_key_id(into.Name)
	string_lookup := make(map[int32]string)

	col := tb.GetColumnInfo(col_id)
	// unpack the string table
	for k, v := range into.StringTable {
		col.StringTable[v] = int32(k)
		string_lookup[int32(k)] = v
	}
	col.val_string_id_lookup = string_lookup

	if into.BucketEncoded {
		for _, bucket := range into.Bins {
			// DONT FORGET TO DELTA UNENCODE THE RECORD VALUES
			prev := uint32(0)
			for _, r := range bucket.Records {
				if into.DeltaEncodedIDs {
					r = r + prev
				}

				cur_set, ok := records[r].SetMap[col_id]
				if !ok {
					cur_set = make(SetField, 0)
				}

				cur_set = append(cur_set, bucket.Value)
				records[r].SetMap[col_id] = cur_set

				records[r].Populated[col_id] = SET_VAL
				prev = r
			}

		}
	} else {
		for r, v := range into.Values {
			cur_set, ok := records[r].SetMap[col_id]
			if !ok {
				cur_set = make(SetField, 0)
				records[r].SetMap[col_id] = cur_set
			}

			records[r].SetMap[col_id] = SetField(v)
			records[r].Populated[col_id] = SET_VAL
		}
	}
}
Exemplo n.º 20
0
// interfaceDecode decodes the next interface value from the stream and returns it.
func interfaceDecode(dec *gob.Decoder) Pythagoras {
	// The decode will fail unless the concrete type on the wire has been
	// registered. We registered it in the calling function.
	var p Pythagoras
	err := dec.Decode(&p)
	if err != nil {
		log.Fatal("decode:", err)
	}
	return p
}
Exemplo n.º 21
0
func receivePerConn(receiver *gob.Decoder, helpChan chan Message) {
	for {
		var foo Message
		err := receiver.Decode(&foo)
		if err == nil {
			fmt.Print("Go Func Received:")
			fmt.Println(foo)
			helpChan <- foo
		}
	}
}
Exemplo n.º 22
0
func (c *GossipChannel) deliverBroadcast(srcName PeerName, _ []byte, dec *gob.Decoder) error {
	var payload []byte
	if err := dec.Decode(&payload); err != nil {
		return err
	}
	data, err := c.gossiper.OnGossipBroadcast(payload)
	if err != nil || data == nil {
		return err
	}
	return c.relayBroadcast(srcName, data)
}
Exemplo n.º 23
0
func deserializeCommon(dec *gob.Decoder, t Type, c *INodeCommon) error {
	if err := dec.Decode(&c.ID); err != nil {
		return fmt.Errorf("Failed to decode ID: %v", err)
	}

	if err := dec.Decode(&c.OrigPath); err != nil {
		return fmt.Errorf("Failed to decode OrigPath: %v", err)
	}

	return nil
}
Exemplo n.º 24
0
func (c *GossipChannel) deliver(srcName PeerName, _ []byte, dec *gob.Decoder) error {
	var payload []byte
	if err := dec.Decode(&payload); err != nil {
		return err
	}
	if data, err := c.gossiper.OnGossip(payload); err != nil {
		return err
	} else if data != nil {
		c.Send(srcName, data)
	}
	return nil
}
Exemplo n.º 25
0
func (c *GossipChannel) deliver(srcName PeerName, _ []byte, dec *gob.Decoder) error {
	var payload []byte
	if err := dec.Decode(&payload); err != nil {
		return err
	}
	update, err := c.gossiper.OnGossip(payload)
	if err != nil || update == nil {
		return err
	}
	c.relay(srcName, update)
	return nil
}
Exemplo n.º 26
0
func negotiateVersion(e *gob.Encoder, d *gob.Decoder) {
	var c Command
	c.Command = CmdVersion
	c.Params = []string{protocolVersion}
	err := e.Encode(c)
	panicOn(err)
	err = d.Decode(&c)
	if c.Params[0] != protocolVersion {
		panic(fmt.Errorf("Mismatched protocol version %s != %s", c.Params[0], protocolVersion))
	}
	panicOn(err)
}
Exemplo n.º 27
0
func (m *Mapper1) Load(decoder *gob.Decoder) error {
	decoder.Decode(&m.shiftRegister)
	decoder.Decode(&m.control)
	decoder.Decode(&m.prgMode)
	decoder.Decode(&m.chrMode)
	decoder.Decode(&m.prgBank)
	decoder.Decode(&m.chrBank0)
	decoder.Decode(&m.chrBank1)
	decoder.Decode(&m.prgOffsets)
	decoder.Decode(&m.chrOffsets)
	return nil
}
Exemplo n.º 28
0
func deserializeDirNodeSnapshot(dec *gob.Decoder) (*DirNode, error) {
	dn := &DirNode{}
	if err := deserializeCommon(dec, DirNodeT, &dn.INodeCommon); err != nil {
		return nil, err
	}

	if err := dec.Decode(&dn.Entries); err != nil {
		return nil, fmt.Errorf("Failed to decode Entries: %v", err)
	}

	return dn, nil
}
Exemplo n.º 29
0
func netReceiver(decoder *gob.Decoder, file *os.File, netInStream chan<- DataInterval, fileStream chan<- DataInterval, deltaReceiverDone chan<- bool) {
	// receive & process data diff
	status := true
	for status {
		var delta FileInterval
		err := decoder.Decode(&delta)
		if err != nil {
			log.Fatal("Protocol decoder error:", err)
			status = false
			break
		}
		log.Debug("receiving delta [", delta, "]")
		if 0 == delta.Len() {
			log.Debug("received end of transimission marker")
			break // end of diff
		}
		switch delta.Kind {
		case SparseData:
			// Receive data
			var data []byte
			err = decoder.Decode(&data)
			if err != nil {
				log.Fatal("Protocol data decoder error:", err)
				status = false
				break
			}
			if int64(len(data)) != delta.Len() {
				log.Fatal("Failed to receive data, expected=", delta.Len(), "received=", len(data))
				status = false
				break
			}
			// Push for writing and vaildator processing
			fileStream <- DataInterval{delta, data}
			netInStream <- DataInterval{delta, data}

		case SparseHole:
			// Push for writing and vaildator processing
			fileStream <- DataInterval{delta, make([]byte, 0)}
			netInStream <- DataInterval{delta, make([]byte, 0)}

		case SparseIgnore:
			// Push for vaildator processing
			netInStream <- DataInterval{delta, make([]byte, 0)}
			log.Debug("ignoring...")
		}
	}

	log.Debug("Server.netReceiver done, sync")
	close(netInStream)
	close(fileStream)
	deltaReceiverDone <- status
}
Exemplo n.º 30
0
func (console *Console) Load(decoder *gob.Decoder) error {
	decoder.Decode(&console.RAM)
	console.CPU.Load(decoder)
	console.APU.Load(decoder)
	console.PPU.Load(decoder)
	console.Cartridge.Load(decoder)
	console.Mapper.Load(decoder)
	var dummy bool
	if err := decoder.Decode(&dummy); err != nil {
		return err
	}
	return nil
}