int CtZrtpSession::enrollAccepted(char *p) {
    if (!isReady || !(streams[AudioStream] != NULL))
        return fail;

    CtZrtpStream *stream = streams[AudioStream];
    int ret = stream->enrollAccepted(p);
    setVerify(true);
    return ret;
}
int CtZrtpSession::enrollDenied() {
    if (!isReady || !(streams[AudioStream] != NULL))
        return fail;

    CtZrtpStream *stream = streams[AudioStream];
    int ret = stream->enrollDenied();
    setVerify(true);                        // TODO : Janis -> is that correct in this case?
    return ret;
}
void CtZrtpSession::setLastPeerNameVerify(const char *name, int iIsMitm) {
    CtZrtpStream *stream = streams[AudioStream];

    if (!isReady || !stream || stream->isStopped)
        return;

    uint8_t peerZid[IDENTIFIER_LEN];
    std::string nm(name);
    stream->zrtpEngine->getPeerZid(peerZid);
    getZidCacheInstance()->putPeerName(peerZid, nm);
    setVerify(1);
}
Exemple #4
0
/*
 * Write data in buffer to disk cache file.
 *
 * This thread is a consumer for the double buffer thread.
 * A conumser must wait until the buffer is not empty, retrieve its
 * data, and then notify the producer that the buffer is not full.
 */
int
DiskCacheWrite(
	FileInfo_t *file,
	int fd)
{
	CircularBuffer_t *writer;
	boolean_t checksum;	/* use checksum enabled on file */
	boolean_t multivolume;	/* staging a multivolume file */
	boolean_t verify;	/* staging a file for data verification */
	sam_ioctl_swrite_t swrite;
	int position;		/* block position for debugging */
	char *out;		/* output buffer pointer */
	int nbytes;
	int nwritten;

/* FIXME comments */
	int copy;
	boolean_t closeDiskcache;
	/* LINTED variable unused in function */
	time_t endTime;
	/* LINTED variable unused in function */
	int secs;

	/* Wait for file to stage. */
	ThreadStateWait(&IoThread->io_writeReady);

	writer = IoThread->io_writer;

	copy = file->copy;

	memset(&swrite, 0, sizeof (sam_ioctl_swrite_t));

	if (GET_FLAG(file->flags, FI_DCACHE)) {
		swrite.offset += file->write_off;
	}

	checksum = ifChecksum(file);
	verify = ifVerify(file);
	multivolume = ifMultiVolume(file);

	dataToWrite = IoThread->io_size;

	cancel = B_FALSE;
	readErrno = 0;
	position = 0;		/* block written to disk for file */

	Trace(TR_FILES, "Write disk inode: %d.%d offset: %lld len: %lld",
	    file->id.ino, file->id.gen, swrite.offset, dataToWrite);

	while (DATA_TO_WRITE()) {

		/*
		 * Wait until the write buffer is not empty.
		 * Retrieve data at 'out' position.
		 * If archive read thread found an error during a read
		 * from media, positioning failure or tar header validation
		 * the error flag will be set in io thead control structure.
		 */
		out = CircularIoAvail(writer, &nbytes, &readErrno);
		if (readErrno != 0) {
			SetErrno = readErrno;
			Trace(TR_ERR,
			    "Error in writer buffer, slot:%d readErrno:%d",
			    CircularIoSlot(IoThread->io_writer, out),
			    readErrno);
			break;
		}

		/* If not a full block of data left to write. */
		if (dataToWrite < nbytes) {
			nbytes = dataToWrite;
		}

		Trace(TR_DEBUG,
		    "Write block: %d buf: %d [0x%x] offset: %lld len: %d",
		    position, CircularIoSlot(IoThread->io_writer, out),
		    (int)out, swrite.offset, nbytes);

		swrite.buf.ptr = out;
		swrite.nbyte = nbytes;

		/* Accumulate checksum value. */
		if (checksum == B_TRUE) {
			Checksum(out, nbytes);
		}

		/* Write data block to disk cache. */
		if (verify == B_FALSE) {
			nwritten = ioctl(fd, F_SWRITE, &swrite);

			if (nwritten != nbytes) {
				Trace(TR_ERR,
				    "Write error: %d fd: %d nbyte: %d "
				    "offset: %lld",
				    errno, fd, swrite.nbyte, swrite.offset);
				/*
				 * Cancel stage request, this will be picked
				 * up in the reader and doublebuffer threads.
				 */
				Trace(TR_MISC,
				    "Cancelled(write error) inode: %d.%d",
				    file->id.ino, file->id.gen);
				SET_FLAG(IoThread->io_flags, IO_cancel);

				if (errno == ECANCELED) {
					cancel = B_TRUE;
					SET_FLAG(file->flags, FI_CANCEL);
				} else {
					readErrno = errno;
					SET_FLAG(file->flags, FI_WRITE_ERROR);
				}
			}
		}

		/*
		 * Wait for checksum thread to complete on the data block
		 * before allowing the double buffer thread to reuse
		 * the 'out' buffer.
		 */
		if (checksum == B_TRUE && nbytes > 0) {
			ChecksumWait();
		}

		/*
		 * Write complete.  Advance write buffer's 'out'
		 * pointer and notify double buffer thread that the buffer
		 * is not empty.
		 */
		CircularIoAdvanceOut(writer);

		file->stage_size += nbytes;
		swrite.offset += nbytes;
		dataToWrite -= nbytes;
		ASSERT_WAIT_FOR_DBX(dataToWrite >= 0);

		position++;

		Trace(TR_DEBUG, "Wrote %d bytes left: %lld (%d/%d)",
		    nbytes, dataToWrite, readErrno, cancel);
	}

	Trace(TR_FILES, "Write disk complete inode: %d.%d",
	    file->id.ino, file->id.gen);

	/*
	 * If no error AND cancel request, close disk cache file.
	 * If no error AND no more VSNs,   close disk cache file.
	 * If error OR more VSNs to stage, save disk cache information.
	 */

	/*
	 * There are a number of scenarios under which to determine
	 * whether to close the disk cache file or leave it open for
	 * a future request.
	 *
	 * If no error AND cancel,		close disk cache file.
	 * If no error AND not multivolume,	close disk cache file.
	 * If no error AND multivolume AND stage_n, close disk cache file.
	 * If error OR more VSNs to stage, 	save disk cache information.
	 */

	/* If no error AND cancel, close disk cache file. */
	if (readErrno == 0 && cancel == B_TRUE) {
		closeDiskcache = B_TRUE;

	/* If no error AND not multivolume, close disk cache file. */
	} else if (readErrno == 0 && multivolume == 0) {
		closeDiskcache = B_TRUE;

	/* If no error AND multivolume AND stage_n, close disk cache file. */
	} else if (readErrno == 0 && multivolume != 0 &&
	    GET_FLAG(file->flags, FI_STAGE_NEVER) &&
	    file->stage_size == file->len) {

		closeDiskcache = B_TRUE;

	/* Else, an error OR more VSNs to stage, save disk cache information. */
	} else {
		/*
		 * If no device available or interrupted system call,
		 * close disk cache.
		 */
		if (readErrno == ENODEV || readErrno == EINTR) {
			closeDiskcache = B_TRUE;
		} else {
			closeDiskcache = B_FALSE;
		}
	}

	/*
	 * Checksumming may have found an error.
	 */
	if (closeDiskcache == B_TRUE && checksum == B_TRUE) {
		/*
		 * Do not check for checksum error if request was
		 * cancelled or an I/O error occurred.
		 */
		if (cancel == B_FALSE && readErrno == 0) {

			readErrno = ChecksumCompare(fd, &file->id);

			if (readErrno != 0) {
				closeDiskcache = B_FALSE;
				swrite.offset = 0;

				if (verify == B_TRUE) {
					SetErrno = 0;	/* set for trace */
					Trace(TR_ERR, "Unable to verify "
					    "inode: %d.%d copy: %d errno: %d",
					    file->id.ino, file->id.gen,
					    copy + 1, readErrno);

					closeDiskcache = B_TRUE;
				}
			} else {
				if (verify == B_TRUE) {
					setVerify(file);
				}
			}

		} else {
			if (verify == B_TRUE) {
				SetErrno = 0;	/* set for trace */
				Trace(TR_ERR, "Unable to verify "
				    "inode: %d.%d copy: %d errno: %d",
				    file->id.ino, file->id.gen,
				    copy + 1, errno);
			}
		}
		checksum = B_FALSE;
	}

	if (closeDiskcache == B_TRUE) {
		(void) close(fd);
		CLEAR_FLAG(file->flags, FI_DCACHE);
		NumOpenFiles--;

	} else {
		SetFileError(file, fd, swrite.offset, readErrno);
		if (checksum == B_TRUE && multivolume != 0) {
			file->csum_val = ChecksumGetVal();
		}
	}

	/* Done writing staged file. */
	ThreadStatePost(&IoThread->io_writeDone);

	return (file->error);
}